Re: CW 9.2 STL memory question.

2003-11-06 Thread Vytautas Leonavicius
VecP p = new Vec[64k]  in this case push_back elements will be allocated on
the heap.

Vec v = Vec[64k] in this case, on the stack, right?

Thanks,

Vytautas

it works, when allocating in this way - Vec v =
 Vec[64k]. Why?

 The vector implementation in MSL doesn't allocate memory until an element
 has been modified or accessed.  This is for efficiency -- you can create a
 vector and if you don't use it, you don't have the allocation overhead.

 -- 
 Ben Combee [EMAIL PROTECTED]
 CodeWarrior for Palm OS technical lead
 Palm OS programming help @ www.palmoswerks.com





-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: CW 9.2 STL memory question.

2003-11-06 Thread Ben Combee
At 02:41 AM 11/6/2003, Vytautas Leonavicius wrote:
VecP p = new Vec[64k]  in this case push_back elements will be allocated on
the heap.
Vec v = Vec[64k] in this case, on the stack, right?
right... of course, it is better to use the syntax

Vec v(64);

as that's constructor initialization, and may avoid the creation of a 
temporary object and the call of a copy constructor which can happen with the

Vec v = Vec(64);

syntax.

--
Ben Combee [EMAIL PROTECTED]
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com 

--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: CW 9.2 STL memory question.

2003-11-05 Thread Ben Combee
At 03:12 AM 11/5/2003, Vytautas Leonavicius wrote:
Hello,

Well, MemPtrNew allocates a maximum of ~64Kb. But when I allocate
std::vector on the stack, I got bad_alloc if I try to allocate more than
~30Kb. But if I use new on vector, that is:
The stack on Palm OS apps is limited to around 4K.

VecP p = new Vec[64k] it works, when allocating in this way - Vec v =
Vec[64k]. Why?
The vector implementation in MSL doesn't allocate memory until an element 
has been modified or accessed.  This is for efficiency -- you can create a 
vector and if you don't use it, you don't have the allocation overhead.

--
Ben Combee [EMAIL PROTECTED]
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com 

--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/