Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   STL container class memory allocation (http://www.velocityreviews.com/forums/t528482-stl-container-class-memory-allocation.html)

Neo 08-11-2007 01:40 PM

STL container class memory allocation
 
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


Barry 08-11-2007 02:05 PM

Re: STL container class memory allocation
 
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.

=?ISO-8859-1?Q?Erik_Wikstr=F6m?= 08-11-2007 02:15 PM

Re: STL container class memory allocation
 
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


All times are GMT. The time now is 07:54 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.