C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how much memory does an empty STL deque occupy?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
R.Z.
Guest





PostPosted: Tue Sep 20, 2005 9:38 am    Post subject: how much memory does an empty STL deque occupy? Reply with quote



i was wondering whether it pays off in term of memory use to store many
empty deques, or is it better to only store deques with size > 0. and does
the size of an empty deque depends on the size of the type of its members
even if the deque is empty?
i've also read that the sizeof operator cannot be used with arrays that
allocate memory dynamically (and there is some dynamic memory allocation
inside of a deque class, isn't it?) so i figured it wouldn't give me correct
size of my deque.

best regards
Remi



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
msalters
Guest





PostPosted: Tue Sep 20, 2005 11:20 am    Post subject: Re: how much memory does an empty STL deque occupy? Reply with quote



R.Z. wrote:

Quote:
I was wondering whether it pays off in term of memory use to store many
empty deques, or is it better to only store deques with size > 0. and does
the size of an empty deque depends on the size of the type of its members
even if the deque is empty?

Possibly. This will depend on the implementation, and I can think of
at least two sane implementations. One does depend, the other doesn't.

Quote:
i've also read that the sizeof operator cannot be used with arrays that
allocate memory dynamically (and there is some dynamic memory allocation
inside of a deque class, isn't it?) so i figured it wouldn't give me correct
size of my deque.

True on all counts.

HTH,
Michiel Salters


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Ulrich Eckhardt
Guest





PostPosted: Tue Sep 20, 2005 2:01 pm    Post subject: Re: how much memory does an empty STL deque occupy? Reply with quote



R.Z. wrote:
Quote:
i was wondering whether it pays off in term of memory use to store many
empty deques, or is it better to only store deques with size > 0. and does
the size of an empty deque depends on the size of the type of its members
even if the deque is empty?

If you wonder if holding a (null-)pointer to a container is more
memory-efficient than holding an empty container, the null pointer will
take less space. If you now compare the overhead of a one-element container
and compare it to a pointer to a one-element container, you will probably
loose, because just the single dynamic allocation of this container already
has lots of overhead.
I wouldn't worry about the useless storage taken by an empty container
unless I really know that I'm short on mem, have many containers and many
of them are empty most of the time. In that case though, I'd first do a
much deeper analysis if one couldn't restructure the whole thing (i.e.
optimizing memory use on the big level) to be more efficient instead of
doing micro-optimizations of memory use.

Quote:
i've also read that the sizeof operator cannot be used with arrays that
allocate memory dynamically (and there is some dynamic memory allocation
inside of a deque class, isn't it?) so i figured it wouldn't give me
correct size of my deque.

sizeof will always yield the size of the object itself, not that of other
memory perhaps referenced by it. When applied to a container, it will
always yield the same size, regardless of how many elements are stored in
the container.

Uli


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.