473,406 Members | 2,867 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,406 software developers and data experts.

Am I deleting correctly question

I have a class that is interacting with some code that takes an array
in the form of pointer to the first object and size of array as
arguments: quick example void foo(*obj o, int size )

I then have a class whose internal structure can be converted to a
primative array

Note: this is an imcomplete class just an example

class X
{
public:
Obj* object; //this is the public interface for the
function that I need to interact with
//example: foo(X.object, X.size)

int objSize; //number of objects in object array
private:
Obj* convertInternalToArray(Internal i)
};

so at some point X says:
this.object = convertInternalToArray(this.internalData)

Now convertInternalToArray creates a tempObj with the keyword new and
does the conversion and returns tempObj.

That means that when convertInternalToArray is called X.object is
pointing to memory on the heap.

Question: since tempObj only has scope in the convertInternalToArray
function I cant get access to it to delete it. If I delete this.object
in the destructor am I cleaning up the memory that was created for
tempObj and then returned to this.object.

Can someone explain to me what is happening with the memory in a
situation like this?

thanks

Oct 11 '06 #1
1 1463
al******@gmail.com wrote:
I have a class that is interacting with some code that takes an array
in the form of pointer to the first object and size of array as
arguments: quick example void foo(*obj o, int size )
The above is syntactically invalid.
public:
Obj* object; //this is the public interface for the
function that I need to interact with
//example: foo(X.object, X.size)

int objSize; //number of objects in object array\\\
private:
Obj* convertInternalToArray(Internal i)
};
Hopefully you have public and private interchanged above, otherwise
it makes no sense at all.
so at some point X says:
this.object = convertInternalToArray(this.internalData)
this is a pointer.
>
Now convertInternalToArray creates a tempObj with the keyword new and
does the conversion and returns tempObj.
>
That means that when convertInternalToArray is called X.object is
pointing to memory on the heap.
If that is where you set it too when you did the new.
Why don't you just declare internally:
vector<Objinternal_object;
and then you don't have to worry so much about screwing up
your allocation (and copying semantics).
>
Question: since tempObj only has scope in the convertInternalToArray
function I cant get access to it to delete it.
"tempObj" only holds the dynamic allocation that new returns. It
doesn't need to be deleted.
>
Can someone explain to me what is happening with the memory in a
situation like this?
I can't explain to you anything unless you give us a little more
complete program because your explanations are incomprehensible
and the what little code you have posted can't possibly be right.
Oct 11 '06 #2

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

Similar topics

6
by: Abhijeet | last post by:
I was just toying around idea of deleting this from a member function. Was expecting that any acess to member variable or function after deleting sould give me dump(segmetation violation).Cause now...
6
by: Matan Nassau | last post by:
Hello. i have a composite which i want to delete. this is a composite which represents a boolean expression (see a previous post of mine with more details at...
14
by: Matthew Wells | last post by:
I'm using this code to delete all relationships in my mdb file iFlag = 1 Do While iFlag <> 0 iFlag = 0 For Each rel In db.Relations db.Relations.Delete rel.Name iFlag = 1 Next rel Loop
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
1
by: jez123456 | last post by:
Hi, I have a windows form with a listbox control. My code all works correctly when deleting an item from the listbox except the last item. I get the following message when trying to delete the...
5
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. ...
46
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this...
8
by: NAdir | last post by:
Hi, thank you for your help. My VB.Net application contains a document that the user can refresh at any time. The refresh works fine and needs to loop through few datatables (hundreds of rows)....
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
4
by: sphinney | last post by:
I'm not exactly sure how to start this post. My question is pretty simple, but it will take a little bit of context before I can state it. (And thanks in advance for taking the time to read this!) ...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.