STL container class memory allocation

N

Neo

Hello,
I have a question on memory allocation for containers. I know what
happens when I ask for a container of a certain size or when the
container grows to accommodate new elements. The question I had is
what does the OS do when an application requests for memory, for ex
from a code using stls? Does the application get what it requests ?
and where does the memory provided reside, will it be in the memory
allocated to the application? or will it enlarge the memory allocated
to the app?


Thanks,
Neo
 
B

Barry

Neo said:
Hello,
I have a question on memory allocation for containers. I know what
happens when I ask for a container of a certain size or when the
container grows to accommodate new elements. The question I had is
what does the OS do when an application requests for memory, for ex

OS?
Not yet

IMHO, they can be layered as the following:

Container
| Standard C++ Library
Allocator
|
(new/delete optional)
---------------------------------------------
|
malloc/free/[alloc/realloc] (seldom used) Standard C Library
|
---------------------------------------------
|
crt implementation calls OS APIs C-Runtime
|
---------------------------------------------
OS

from a code using stls? Does the application get what it requests ?

memory may exhaust, so allocation may fail, the failure passed up from
OS API calls to the upper layers
and where does the memory provided reside, will it be in the memory
allocated to the application?

It depends, like vector deque, at a certain time they have memory reside
like set list, they don't
or will it enlarge the memory allocated
to the app?

But I guess your using "application" here is not appropriate, forgive my
English, I can't describe this to you.
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hello,
I have a question on memory allocation for containers. I know what
happens when I ask for a container of a certain size or when the
container grows to accommodate new elements. The question I had is
what does the OS do when an application requests for memory, for ex
from a code using stls? Does the application get what it requests ?
and where does the memory provided reside, will it be in the memory
allocated to the application? or will it enlarge the memory allocated
to the app?

It would be possible to answer these questions, however to do so you
first have to assume that there is an OS, that might not be the case. Or
put in another way, the answer to this question is platform dependent
and off-topic here, for a better answer try a group dealing with your
platform, such as comp.os.ms-windows.programmer.win32.

A hint though, the standard containers use the same allocator as you do
when you use new (unless otherwise specified), which reduces the
question to how memory is allocated on you platform.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top