STL container class memory allocation

Discussion in 'C++' started by Neo, Aug 11, 2007.

  1. Neo

    Neo Guest

    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
    Neo, Aug 11, 2007
    #1
    1. Advertising

  2. Neo

    Barry Guest

    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.
    Barry, Aug 11, 2007
    #2
    1. Advertising

  3. 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
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Aug 11, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maitre Bart
    Replies:
    2
    Views:
    518
    Maitre Bart
    Feb 11, 2004
  2. Ken
    Replies:
    24
    Views:
    3,856
    Ben Bacarisse
    Nov 30, 2006
  3. chris
    Replies:
    6
    Views:
    985
    chris
    Oct 28, 2005
  4. Replies:
    4
    Views:
    794
    Daniel T.
    Feb 16, 2006
  5. wolverine
    Replies:
    2
    Views:
    445
    Marcus Kwok
    Jul 24, 2006
Loading...

Share This Page