473,320 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Memory occupied by Map

Hi

I want to know the memory occupied by STL Map, Is there a way to do
that.

I have written a sample application and adding value to map doesnot
change size
map<int,intmapInt2Int;
mapInt2Int[1]=2;
mapInt2Int[2]=2;
mapInt2Int[3]=2;
mapInt2Int[4]=2;
mapInt2Int[5]=2;
mapInt2Int[6]=2;
size_t sz= sizeof(mapInt2Int);
How can I find how much bytes does the map uses.

My main requirement is to store the map as a byte blob in database and
rettrieve back.

any thoughts???
Jun 27 '08 #1
4 4225
"al********@gmail.com" <al********@gmail.comwrote:
I have written a sample application and adding value to map doesnot
change size
sizeof() returns the *static* size of an object/type, the value is
determined at compile time and never changes.
How can I find how much bytes does the map uses.
You can't do it in any portable way. If you want a solution specific to
your environment, you will have to ask in a newsgroup that specializes
in such information.
My main requirement is to store the map as a byte blob in database and
rettrieve back.
That doesn't sound like a very good idea. A map is an associative array,
so is a database table. Why not store the former as the latter?
Jun 27 '08 #2
well i think the solution to get size is to iterate the map and and
get size of each element
this is the only way i can this right now
basic idea is i need to serialize the map contents so planning to
store as byte blob in db
Jun 27 '08 #3
On Jun 13, 3:01 am, "Daniel T." <danie...@earthlink.netwrote:
"alien.0...@gmail.com" <alien.0...@gmail.comwrote:
I have written a sample application and adding value to map doesnot
change size
sizeof() returns the *static* size of an object/type, the value is
determined at compile time and never changes.
How can I find how much bytes does the map uses.
You can't do it in any portable way.
You can, sort of. You write a custom allocator which tracks how
much is allocated, and instantiate the map with that.

Whether the information is in anyway useful, of course, is
another issue.

[...]
My main requirement is to store the map as a byte blob in
database and rettrieve back.
That doesn't sound like a very good idea. A map is an
associative array, so is a database table. Why not store the
former as the latter?
For example. More significantly, of course, an std::map is
*not* a byte blob, so it can't be stored directly as such. If
for any reason you need to store it as a byte blob in a
database, you'll first have to marshal it.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orient�e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34
Jun 27 '08 #4
In article <e23aebaa-b2d6-4df6-93a8-1b2e9f5933c3
@p25g2000hsf.googlegroups.com>, al********@gmail.com says...
well i think the solution to get size is to iterate the map and and
get size of each element
this is the only way i can this right now
basic idea is i need to serialize the map contents so planning to
store as byte blob in db
Knowing how much memory the map occupies won't really do you any good. A
map is (at least normally) implemented as a balanced binary tree that
includes pointers to nodes and balancing information in each node along
with the data you really care about. When you serialize the data, you
just want to store the real data, not the pointers or balancing data.

I'd start by copying the data from the map into a vector:

std::vector<your_map::value_typedata;

std::copy(your_map.begin(), your_map.end(),
std::back_inserter(data));

size_t BLOB_size = sizeof(your_map::value_type) * data.size();

Then to serialize the data, you copy the data directly from the vector
to the database.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Birgit Rahm | last post by:
Hello newsgroup, I am a beginner, so I am asking maybe immoderate questions. I want to delete a variable, after filling it with complex objects. How should I do it? e.g. AAA = AAA = Can I...
11
by: Viktor | last post by:
Which GUI is the most stable one? I don't need any fancy looking widgets (look and feel doesn't realy matter to me), I "just" need it to be rock stable and fast...
2
by: anand | last post by:
hi, i am fetching data from database using dataadaptor and filling up a dataset. i checked memory usage of the app, and it consumes 50 Mb of RAM for the given amount of data. that is, i checked...
1
by: trialproduct2004 | last post by:
Hi all, I am having slight confusion regarding memory management in .net. Say suppose i have two application one is in C# and other is in MFC(VC++). Both of this application are using lots...
18
by: Jan | last post by:
Hi there, i've got an STL map with something like this ( map<string, Object*> xyz; ) What happens when I call xyz.clear()? Is only the map cleared or the map and the Objects, so that the memory...
1
by: prashant_sharma | last post by:
Hi, Following code is creating assertion Please help me to release memory occupied by Char array.. char *nm = new char; strcpy(nm,"Prashant"); delete nm; Thanks in Advance
3
by: somaskarthic | last post by:
Hi How to release the memory occupied by string vector in c++? Its very urgent . Pls post your replies? Thanks in advance somaskarthic
0
by: somaskarthic | last post by:
Hi I need to get the system memory (not harddisk storage space) occupied by my c++ application ? Is there any readily available methods to find the memory currently occupied by the application ? ...
39
by: Ravi | last post by:
Can you all please suggest a program which tell us the range of memry addresses occupied by the given c program?
1
by: Lambda | last post by:
I'm trying to develop several interesting components of a simple search engine follow some text books. A book introduces some ways to compress dictionary, allow it to stay on main memory. In...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.