By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,967 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,967 IT Pros & Developers. It's quick & easy.

STL container class memory allocation

P: n/a
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

Aug 11 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Neo wrote:
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.
Aug 11 '07 #2

P: n/a
On 2007-08-11 15:40, Neo wrote:
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.

--
Erik Wikström
Aug 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.