Click here to Skip to main content
15,895,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: VC++ 6.0 question newbie question Pin
Ozer Karaagac5-Mar-08 3:37
professionalOzer Karaagac5-Mar-08 3:37 
GeneralRe: VC++ 6.0 question newbie question Pin
johnny alpaca5-Mar-08 23:47
johnny alpaca5-Mar-08 23:47 
GeneralRe: VC++ 6.0 question newbie question Pin
toxcct5-Mar-08 3:39
toxcct5-Mar-08 3:39 
QuestionRe: VC++ 6.0 question newbie question Pin
David Crow5-Mar-08 8:40
David Crow5-Mar-08 8:40 
GeneralRe: VC++ 6.0 question newbie question Pin
toxcct5-Mar-08 21:14
toxcct5-Mar-08 21:14 
QuestionRe: VC++ 6.0 question newbie question Pin
David Crow6-Mar-08 4:18
David Crow6-Mar-08 4:18 
GeneralRe: VC++ 6.0 question newbie question Pin
toxcct6-Mar-08 4:20
toxcct6-Mar-08 4:20 
Generalredundant allocation Pin
George_George5-Mar-08 2:45
George_George5-Mar-08 2:45 
Hello everyone,


Quoted from GotW #54 about redundant allocation in vector and deque. What makes me confused is "because none of the allocations are redundant". I think it means,

The context is about adding new elements at the end, not about insert elements at any arbitrary location (e.g. in the middle), right?

1. For deque, when allocating memory for new elements at the end, no need to reallocate, i.e. allocate new space, copy old elements to new space and free old memory -- so no redundant allocation for existing component again;

2. For vector, when allocating memory for new elements at the end, when capacity == current size, need to reallocate, i.e. allocate new space, copy old elements to new space and free old memory -- so redundant allocation for existing components again.

My understanding correct?

http://www.gotw.ca/gotw/054.htm

--------------------
3. A deque is easier to use, and inherently more efficient for growth, than a vector. The only operations supplied by vector that deque doesn't have are capacity() and reserve() -- and that's because deque doesn't need them! For vector, calling reserve() before a large number of push_back()s can eliminate reallocating ever-larger versions of the same buffer every time it finds out that the current one isn't big enough after all. A deque has no such problem, and having a deque::reserve() before a large number of push_back()s would not eliminate any allocations (or any other work) because none of the allocations are redundant; the deque has to allocate the same number of extra pages whether it does it all at once or as elements are actually appended.
--------------------


thanks in advance,
George
GeneralRe: redundant allocation [modified] Pin
toxcct5-Mar-08 4:10
toxcct5-Mar-08 4:10 
GeneralRe: redundant allocation Pin
George_George5-Mar-08 18:29
George_George5-Mar-08 18:29 
GeneralRe: redundant allocation Pin
toxcct5-Mar-08 21:16
toxcct5-Mar-08 21:16 
GeneralRe: redundant allocation Pin
George_George5-Mar-08 21:39
George_George5-Mar-08 21:39 
GeneralTruncate a number with decimals Pin
piul5-Mar-08 1:57
piul5-Mar-08 1:57 
GeneralRe: Truncate a number with decimals Pin
Cedric Moonen5-Mar-08 2:02
Cedric Moonen5-Mar-08 2:02 
GeneralRe: Truncate a number with decimals Pin
piul5-Mar-08 2:06
piul5-Mar-08 2:06 
GeneralRe: Truncate a number with decimals Pin
CPallini5-Mar-08 2:13
mveCPallini5-Mar-08 2:13 
GeneralRe: Truncate a number with decimals Pin
CPallini5-Mar-08 2:09
mveCPallini5-Mar-08 2:09 
GeneralRe: Truncate a number with decimals Pin
piul5-Mar-08 2:14
piul5-Mar-08 2:14 
GeneralRe: Truncate a number with decimals Pin
CPallini5-Mar-08 2:17
mveCPallini5-Mar-08 2:17 
GeneralRe: Truncate a number with decimals Pin
Eric Pruneau5-Mar-08 5:33
Eric Pruneau5-Mar-08 5:33 
GeneralProblem with Release Mode Pin
ritz12345-Mar-08 1:49
ritz12345-Mar-08 1:49 
GeneralRe: Problem with Release Mode Pin
Cedric Moonen5-Mar-08 2:00
Cedric Moonen5-Mar-08 2:00 
GeneralRe: Problem with Release Mode Pin
CPallini5-Mar-08 2:00
mveCPallini5-Mar-08 2:00 
GeneralRe: Problem with Release Mode Pin
_AnsHUMAN_ 5-Mar-08 2:01
_AnsHUMAN_ 5-Mar-08 2:01 
QuestionHow to get the username associated with a process using win32 apis Pin
vineeshV5-Mar-08 1:24
vineeshV5-Mar-08 1:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.