Object Data and pointer assignments [message #19320] |
Thu, 09 March 2000 00:00  |
Ben Tupper
Messages: 186 Registered: August 1999
|
Senior Member |
|
|
Hello,
I am in the middle of wrtting my first object from scratch. Scratch is
a good word since I'm doing a lot of that on my head. I'm hoping to get
some advice on organization of data. I need 4 pieces of data (one 2d
arrays and two structures that vary in size according to the size of the
arrays) plus six keywords that I need to get/set. Currently, I have
defined each of the 3 bits of data as null pointers in the BLAH__DEFINE
procedure.
In the BLAH::INIT function, the user passes one of the two arrays as an
argument. At that point I reassign one of the pointers to...
Self.InArray = Ptr_New(InArray).
I think I understand why I can reassign the structure field when going
from a null pointer to a filled pointer. On second thought, I don't
understand it but I can accept that it works. It's the next step I need
help on.
I would like to change the contents of this field later to some other
value (a differently sized array.) Here's where the ice under me gets
very very thin and my eyes get misty. In the BLAH::SETPROPERTY method,
I don't know if I should free this pointer before reassigning (and does
that leave the structure field undefined?), or if I should simply
overwrite it as I did in the INIT function. If I reassign the filed
to a new pointer, what happens to the previously occupied heap space?
Have I sprung a leak?
Thanks!
Ben
--
Ben Tupper
Bigelow Laboratory for Ocean Science
tupper@seadas.bigelow.org
pemaquidriver@tidewater.net
|
|
|
Re: Object Data and pointer assignments [message #19990 is a reply to message #19320] |
Mon, 15 May 2000 00:00  |
promashkin
Messages: 169 Registered: December 1999
|
Senior Member |
|
|
David Fanning wrote:
> My oldest son got a girlfriend and
> a driver's license within days of one another. Now
> *that* is something worth worrying about. :-(
For as long as he has only a license and no car, they will be just fine :-)
Cheers,
Pavel
|
|
|
Re: Object Data and pointer assignments [message #20033 is a reply to message #19320] |
Thu, 11 May 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Brad Gom (b_gom@hotmail.com) writes:
>> To reassign the pointer to something else (after it has been
>> defined by the INIT method), you simple de-reference the pointer:
>>
>> *self.InArray = newStruct
>>
>> You don't leak any memory because IDL is managing this
>> whole process for you.
>
> Thanks for clearing this up, David. These details didn't exactly jump out of
> the manuals at me.
No. Not exactly. :-)
> On a related topic, does anyone know if it is possible to leak memory without
> beeing able to see any lost heap variables with the 'help,/heap' command? I
> find that in a couple IDL programs that deal with shuffling large chunks of
> data back and forth in memory, IDL does not seem to free all the memory it
> uses back to the system. ie. When I monitor the memory usage with the Windows
> NT task manager, the amount of used memory climbs each time the IDL program is
> executed, and doesn't fall all the way back down -even though there doesn't
> seem to be anything in the heap. When I shut down IDL, all the memory gets
> freed.
*NO* IDL process (and I include IDL for Windows) gives
memory back to the operating system while the process is
running. What you are seeing is more likely the result of
poor memory management inside a program module (e.g.,
not undefining an image variable when you are done with
it before reading another one, etc.) than it is any
leaking memory.
> Is this something I should worry about, or is it just a consequence of running
> in Windows? The memory 'loss' isn't severe, but I worry that my program is
> losing track of memory somehow.
Is is something you should worry about? Well, don't
you own any Microsoft stock or something *really* worth
worrying about? My oldest son got a girlfriend and
a driver's license within days of one another. Now
*that* is something worth worrying about. :-(
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: Object Data and pointer assignments [message #20036 is a reply to message #19320] |
Thu, 11 May 2000 00:00  |
promashkin
Messages: 169 Registered: December 1999
|
Senior Member |
|
|
Brad Gom wrote:
> When I monitor the memory usage with the Windows
> NT task manager, the amount of used memory climbs each time the IDL program is
> executed, and doesn't fall all the way back down -even though there doesn't
> seem to be anything in the heap. When I shut down IDL, all the memory gets
> freed.
I gave up on memory checks. On my Mac, I have two system monitors, and
they give me different results if run at the same time. One tells me my
OS is using 34 Mb, another - 58 Mb. Pretty significant, huh? My
Microsoft Word, just idle, sometimes increases memory use for no
apparent reason, likely reflecting the predatory nature of the company itself.
For IDL, in Windows, I am not even concerned with that, I never ran out
of memory yet, despite my humble 64 Mb of RAM. On a Mac I do (despite
its 256 Mb of RAM), since it will not reallocate RAM. Oh well. Its a Mac
thing, no NT user can understand :-) I guess Apple guys think it
empowers the user, when he is to keep track of how much memory his
applications use :-(
Cheers,
Pavel
|
|
|
Re: Object Data and pointer assignments [message #20039 is a reply to message #19320] |
Thu, 11 May 2000 00:00  |
Brad Gom
Messages: 49 Registered: August 1997
|
Member |
|
|
David Fanning wrote:
> To reassign the pointer to something else (after it has been
> defined by the INIT method), you simple de-reference the pointer:
>
> *self.InArray = newStruct
>
> You don't leak any memory because IDL is managing this
> whole process for you.
Thanks for clearing this up, David. These details didn't exactly jump out of
the manuals at me.
On a related topic, does anyone know if it is possible to leak memory without
beeing able to see any lost heap variables with the 'help,/heap' command? I
find that in a couple IDL programs that deal with shuffling large chunks of
data back and forth in memory, IDL does not seem to free all the memory it
uses back to the system. ie. When I monitor the memory usage with the Windows
NT task manager, the amount of used memory climbs each time the IDL program is
executed, and doesn't fall all the way back down -even though there doesn't
seem to be anything in the heap. When I shut down IDL, all the memory gets
freed.
Is this something I should worry about, or is it just a consequence of running
in Windows? The memory 'loss' isn't severe, but I worry that my program is
losing track of memory somehow.
Thanks
Brad
|
|
|