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

re-allocating arrays in /clr

I'm using VS C++.NET 2005 Express in /clr mode. Say I have a PointF array:

array<PointF>^ point_array = gcnew array<PointF>(100) ;

Now I want to re-allocate point_array, and in doing so also free up the
previous array's points. Is this sufficient:

point_array = gcnew array<PointF>(999) ; // new array

or do I need to tell the system I'm doing this, ala something like:

delete point_array ;
point_array = nullptr ;

I'm guessing just re-allocating (or pointing) to something new will
automatically free up the elements in the array since the elements
themselves are instances of a ref class. But I want to be sure.

I'll point out that both of the following lines compile, but I don't believe
they both would work when executed (i.e., one or both would cause a program
crash):

delete point_array ;
delete [] point_array ;

and I'm not sure, but probable just doing:

point_array = nullptr ;

or

point_array = some_other_point_array ;

would also free up the points that were in the original array, and in the
case of setting it to nullptr would make the variable 'point_array'
available for re-allocation. Note, I'm not concerned whether garbage
collection decides to immediately free up the resource memory, just that
it's legal for me to re-assign or re-allocate the pointer to the array
without causing problems.

Thanks in advance for any responses!

[==P==]

Nov 17 '05 #1
1 1415
You can do a delete before doing the gcnew - but since the array does not
have a destructor, it won't really serve any purpose. Leave it to the GC to
collect the orphaned array as and when it pleases to do so :-)

--
Regards,
Nish [VC++ MVP]
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:eA**************@TK2MSFTNGP12.phx.gbl...
I'm using VS C++.NET 2005 Express in /clr mode. Say I have a PointF array:

array<PointF>^ point_array = gcnew array<PointF>(100) ;

Now I want to re-allocate point_array, and in doing so also free up the
previous array's points. Is this sufficient:

point_array = gcnew array<PointF>(999) ; // new array

or do I need to tell the system I'm doing this, ala something like:

delete point_array ;
point_array = nullptr ;

I'm guessing just re-allocating (or pointing) to something new will
automatically free up the elements in the array since the elements
themselves are instances of a ref class. But I want to be sure.

I'll point out that both of the following lines compile, but I don't
believe they both would work when executed (i.e., one or both would cause
a program crash):

delete point_array ;
delete [] point_array ;

and I'm not sure, but probable just doing:

point_array = nullptr ;

or

point_array = some_other_point_array ;

would also free up the points that were in the original array, and in the
case of setting it to nullptr would make the variable 'point_array'
available for re-allocation. Note, I'm not concerned whether garbage
collection decides to immediately free up the resource memory, just that
it's legal for me to re-assign or re-allocate the pointer to the array
without causing problems.

Thanks in advance for any responses!

[==P==]

Nov 17 '05 #2

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

Similar topics

1
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
1
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
10
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
1
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id ...
3
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.