Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > questions about dynamic allocations

Reply
Thread Tools

questions about dynamic allocations

 
 
luke_2003
Guest
Posts: n/a
 
      06-04-2004
**** Post for FREE via your newsreader at post.usenet.com ****

I have a pointer to point to data array.

I have a for loop. And I need to define different array size in the for
loop.

for example:

iter=4;
float **xp;

for(int i=0; i<4; i++){

xs1=(int)(floor(xdim/(iter-i)));
ys1=(int)(floor(ydim/(iter-i)));

xp=new float *[xs1];
for(j=0; j<xs1; j++){
xp[j]=new float[ys1];
}

//implementations
}

My question is where should I delete the pointer, inside of the for loop or
outside of the for loop.

If outside of the for loop, what happend to those allocated memory at each
for loop.

Thanks!


Luke



-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
http://www.usenet.com
Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      06-04-2004
On Thu, 3 Jun 2004 20:40:25 -0400, "luke_2003" <(E-Mail Removed)>
wrote:

>**** Post for FREE via your newsreader at post.usenet.com ****
>
>I have a pointer to point to data array.
>
>I have a for loop. And I need to define different array size in the for
>loop.
>
>for example:
>
>iter=4;
>float **xp;
>
>for(int i=0; i<4; i++){
>
> xs1=(int)(floor(xdim/(iter-i)));
> ys1=(int)(floor(ydim/(iter-i)));
>
> xp=new float *[xs1];


You obviously want comp.lang.c++, down the hall, 2nd door on the
right, but watch out for the wet paint on the door knob.

> for(j=0; j<xs1; j++){
> xp[j]=new float[ys1];
> }
>
>//implementations
>}
>
>My question is where should I delete the pointer, inside of the for loop or
>outside of the for loop.


You delete your pointers only after you are done using the memory they
point to.

>
>If outside of the for loop, what happend to those allocated memory at each
>for loop.


Nothing. Allocated memory remains allocated until you deallocate it.

>
>Thanks!
>
>
>Luke
>
>
>
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> *** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
> http://www.usenet.com
>Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=




<<Remove the del for email>>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reuse HashMap$Entry (or HashMap in total) to avoid millions of allocations Vince Darley Java 4 03-02-2010 07:48 AM
tracking memory allocations by class Manuel Massing C++ 1 07-16-2004 11:23 AM
Disk-backed allocations or collections GG Java 4 07-02-2004 05:24 AM
Re: questions about dynamic allocations luke_2003 C Programming 1 06-05-2004 12:37 AM
Heap vs Stack allocations MSG C++ 23 01-29-2004 07:56 AM



Advertisments