473,569 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL container class memory allocation

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
2 2059
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 "applicatio n" here is not appropriate, forgive my
English, I can't describe this to you.
Aug 11 '07 #2
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.program mer.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2059
by: Sensei | last post by:
Hi! I'm looking for something similar to the map container, but with a slight modification, a unique key, with multiple assignments to each one. I think some container in the STL has it, but I cannot see it. So I can assign to a key like a map: // pseudo c++ code container<int, int> m;
6
2451
by: daveb | last post by:
I'm trying to write some code that calls the constructors of STL containers explicitly, and I can't get it to compile. A sample program is below. One compiler complains about the last two lines (the map constructor calls), saying that I'm trying to take the address of a constructor. Another compiler complains about all four of the last...
7
4681
by: toton | last post by:
Hi, I have a STL vector of of characters and the character class has a Boost array of points. The things are vector<Characterchars; and class Character{ private: array<Point,Npoints; }; Now are the memory layout is contiguous? i.e all the character resides side by side just like array, and all Points side by side insede the
7
20001
by: toton | last post by:
Hi, I want a circular buffer or queue like container (queue with array implementation). Moreover I want random access over the elements. And addition at tail and remove from head need to be low cost. STL vector is suitable for removing form tail? or it is as costly as removing from middle? any other std container to serve this purpose?...
6
3546
by: Marvin Barley | last post by:
I have a class that throws exceptions in new initializer, and a static array of objects of this type. When something is wrong in initialization, CGI program crashes miserably. Debugging shows uncaught exception. How to catch an exception that happened before main() try { ... } catch (...) { ... } block? Is there a way?
7
3117
by: ademirzanetti | last post by:
Hi there !!! I would like to listen your opinions about inherit from a STL class like list. For example, do you think it is a good approach if I inherit from list to create something like "myList" as in the example below ? #include "Sector.h" using namespace boost;
18
2193
by: tech | last post by:
Hi, i have a std::vector of pointers to base classes say std::vector<element*m_elements; how do i make the followin exception safe function() { element* e= new DerivedElement; m_elements.push_back(element); }
36
2011
by: Peter Olcott | last post by:
So far the only way that I found to do this was by making a single global instance of the container class and providing access to the contained class, through this single global instance. Are there any other no-overhead ways that a contained class can access its container? The obvious choice of passing (a pointer or a reference to the...
9
2626
by: Steven Powers | last post by:
Imagine the following setup class Parent { virtual void doStuff(); } class Child : public Parent { virtual void doStuff(); }
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.