Hi all!
So I'm trying to determine how much memory is being used by the
following class member in my code:
vector<map<unsigned int, double
Would the snippet below be the right way of going about this?
---- BEGIN SNIPPET ----
vector<map<unsigned int,double my_data
// fill my_data up with some, erm... data, then...
int mem_used(0);
mem_used += sizeof(vector<map<unsigned int,double);
mem_used += my_data.capacity()*sizeof(map<unsigned int,double>);
for (int i=0; i<my_data.size(); i++) mem_used +=
my_data[i].size()*(sizeof(unsigned int)+sizeof(double));
---- END SNIPPET ----
Would appreciate your comments and suggestions as a sanity check.
Thanks in advance!
--
Murtaza Gulamali 5 4917
mygulamali wrote:
So I'm trying to determine how much memory is being used by the
following class member in my code:
vector<map<unsigned int, double
Would the snippet below be the right way of going about this?
---- BEGIN SNIPPET ----
vector<map<unsigned int,double my_data
// fill my_data up with some, erm... data, then...
int mem_used(0);
mem_used += sizeof(vector<map<unsigned int,double);
mem_used += my_data.capacity()*sizeof(map<unsigned int,double>);
for (int i=0; i<my_data.size(); i++) mem_used +=
my_data[i].size()*(sizeof(unsigned int)+sizeof(double));
---- END SNIPPET ----
Would appreciate your comments and suggestions as a sanity check.
The only sure way would be very platform- and compiler-specific.
Many platforms and different implementations allow you to obtain
the amount of "available" memory by calling a specific function
(not a standard C++ function). Call it before and after your object
is initialised, and that should give you the closest reading on the
memory consumption of your particular type. Any other attempts,
either involving 'sizeof' or any other means do not account for
possible other allocations 'vector' or 'map' does to exist.
IOW, to get the full picture on implementation-specific behaviour
you need implementation-speicific means.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Jun 18, 1:19 pm, mygulamali <mygulam...@gmail.comwrote:
So I'm trying to determine how much memory is being used by the
following class member in my code:
vector<map<unsigned int, double
You can't. It's unspecified, and there's not really any way of
getting a reliable measure. (You can provide custom allocators,
which track, but that doesn't tell you how much you use with the
standard allocators, and of course, how much you use may depend
on how you've filled the array, etc.)
Would the snippet below be the right way of going about this?
---- BEGIN SNIPPET ----
vector<map<unsigned int,double my_data
// fill my_data up with some, erm... data, then...
int mem_used(0);
mem_used += sizeof(vector<map<unsigned int,double);
mem_used += my_data.capacity()*sizeof(map<unsigned int,double>);
for (int i=0; i<my_data.size(); i++) mem_used +=
my_data[i].size()*(sizeof(unsigned int)+sizeof(double));
---- END SNIPPET ----
It will give you a minimum size, but it doesn't take into
account all of the additional overheads that are be present.
--
James Kanze (GABI Software, from CAI) 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
On 18 Jun, 12:19, mygulamali <mygulam...@gmail.comwrote:
>
vector<map<unsigned int,double my_data
// fill my_data up with some, erm... data, then...
int mem_used(0);
mem_used += sizeof(vector<map<unsigned int,double);
mem_used += my_data.capacity()*sizeof(map<unsigned int,double>);
the only think standard says is that capacity() returns
number of objects that vector can store without requiring
reallocation. nothing about the total allocated memory.
for (int i=0; i<my_data.size(); i++) mem_used +=
my_data[i].size()*(sizeof(unsigned int)+sizeof(double));
sizeof(map<unsigned int,double>::value_type) does
not have to be equal to sizeof(unsigned int)+sizeof(double)
sizeof(map<unsigned int,double>::value_type) depends on
its implementation and its alignment.
Would appreciate your comments and suggestions as a sanity check.
If you want to find out exact memory requirement you
will have to write your own allocator that tracks allocated
size and use it for both your vector and map.
regards
DS
Thank you all for your replies!
Ok, so I understand that I will probably need to write my own
allocators to assess true and precise memory usage. But do you think
the snippet I submitted above would be sufficient to assess the
maximum amount of memory that is being allocated for use by my object
(the vector of maps)?
In any case, I guess I'll have to get myself a copy of Intel VTune
Analyzer and perform some profiling tests on my code.
Thanks again!
--
Murtaza Gulamali
On 19 Jun, 10:18, mygulamali <mygulam...@gmail.comwrote:
Thank you all for your replies!
Ok, so I understand that I will probably need to write my own
allocators to assess true and precise memory usage. But do you think
the snippet I submitted above would be sufficient to assess the
maximum amount of memory that is being allocated for use by my object
(the vector of maps)?
not maximum, not real, only theoretical minimum.
In any case, I guess I'll have to get myself a copy of Intel VTune
Analyzer and perform some profiling tests on my code.
Thanks again!
--
Murtaza Gulamali
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mosfets |
last post by:
Hi,
I'm having a little trouble figuring out the difference in terms of
memory allocation between:
class person_info;
class A {
private:
|
by: juvi |
last post by:
Hi,
is there a tool for Vector Graphics Maps creation? (maybe a free version?)
If yes: Can I use the created map with Microsoft MapPoint? Would it be
possible to create a map of a building and...
|
by: ivan.leben |
last post by:
How can I really delete a preloaded image from memory/disk cache? Let's
say I preload an image by creating an Image object and setting its src
attribute to desired URL:
var img = new Image();...
|
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...
|
by: christophe.chazeau |
last post by:
Hi,
I have a problem with a really simple chunk of code which should work
but does obviously does not.
This chunk of code is just a POC aimed at finding a bug in a larger
project in which the...
|
by: CMOS |
last post by:
one of the projects im working in currently requires use of ultra
large sized maps, lists, vector, etc. (basically stl containers).
Sizes might grow up to 1000 Million entries. since it is...
|
by: abir |
last post by:
I have a big dynamic sparse directed graph implementation where new
nodes are added & old nodes are removed. Usually, at any moment of
time the number of nodes in the graph and the number of edges...
|
by: cham |
last post by:
Hi,
I am working on c++ in a linux system ( Fedora core 4 ),
kernel version - 2.6.11-1.1369_FC4
gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 )
In my code i am creating a vector to store...
|
by: jacek.dziedzic |
last post by:
Hi!
I need to be able to track memory usage in a medium-sized
application I'm developing. The only significant (memory-wise) non-
local objects are of two types -- std::vector<and of a custom...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
| |