473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

questions about dynamic allocations

**** 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
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Nov 14 '05 #1
1 954
On Thu, 3 Jun 2004 20:40:25 -0400, "luke_2003" <kh***@engr.uky.edu>
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>>
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
by: Pat | last post by:
Hi, 1. Any faster method (other than for-loop) to initialize array? 2. Does there have similar C++ function to replace C's "fprintf"? Thanks. Pat
6
by: chris | last post by:
Hi all, I need to know, what is the difference between dynamic memory allocation, and stack allocation ? 1. If I have a class named DestinationAddress, when should I use dynamic memory...
2
by: collinm | last post by:
hi i expect to find 7 file on a folder... maybe less, maybe more... i can surely put this number to 1... but i think doing some realloc will be expensive... after 7 files, i need to use...
14
by: placid | last post by:
Hi all, i have this struct for a binary tree node typedef struct treenode { char *word; struct treenode *right; struct treenode *left; }TreeNode;
3
by: WHY | last post by:
Since there's no way to create a c# method with optional, or nullable parameters. And since you can't write an overloaded web method. Is it possible to edit the WSDL in conjunction with a c#...
4
by: Mark Healey | last post by:
I'd like to allocate some memory for a two dimensional array. The problem is that whenever I try to use pointer arithmetic I screw up. I just want to use conventional array type statements to get...
0
by: Jobs | last post by:
All answers to the below interview questions are at http://www.geocities.com/dotnetinterviews/ or you can download the complete answer zip file from...
12
by: googlinggoogler | last post by:
Hi, Im new to C++ and trying to self teach myself whilst I sit at my unentertaining day job (thought i'd put that across before im accused of cheating on my homework, im 45...) Anyway I'm...
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
6
by: Peeyush81 | last post by:
Hi All, I am trying to invoke methods in c++ code in two ways, one by compiling the calling code with the called code and running it standalone, other by making a dll of the called code and then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
1
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...
0
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...
0
marktang
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.