protcoop@leibniz.uucp (07/24/89)
I am trying to use AllocRemember/FreeRemember to keep track of all the
resources that I allocate, but it does not seem to work properly. Here
is what I have .
In the main function in one file I have ...
struct Remember *resources = (struct Remember*)NULL;
In a second file, I have the following:
extern struct Remember *resources;
.....
tgad = AllocRemember( resources, sizeof(struct Gadget), MEMF_CHIP );
In a third file:
extern struct Remember *resources;
......
if (resources)
{
printf("memory freed\n");
FreeRemember( resources, TRUE );
}
The printf never gets executed so the memory is not freed. The only
memory I allocate is for eight gadgets (as in above call). The system
loses 512 bytes each time. I am new to these functions and would
appreciate any help as to what I am doing wrong. Thank You.
Alan W. McKay | My opinions are mine, yours are yours. | Eat Food |
NEPEAN, Ont. | I in no way pretend to represent the | and |
613-763-8980 | the options of my employer. So there. | LIVE !! |
kevin@cbmvax.UUCP (Kevin Klop) (07/25/89)
In article <784@bnr-fos.UUCP> protcoop@leibniz.uucp () writes: >In a second file, I have the following: > >extern struct Remember *resources; >..... >tgad = AllocRemember( resources, sizeof(struct Gadget), MEMF_CHIP ); You need to pass the ADDRESS of resources. Thus, the call should be: tgad = AllocRemember(&resources, sizeof(struct GFadget), MEMF_CHIP); > > >In a third file: >extern struct Remember *resources; >...... >if (resources) >{ > printf("memory freed\n"); > FreeRemember( resources, TRUE ); >} This should work fine with the above change. -- Kevin -- Kevin Klop {uunet|rutgers|amiga}!cbmvax!kevin Commodore-Amiga, Inc. The number, 111-111-1111 has been changed. The new number is: 134-253-2452-243556-678893-3567875645434-4456789432576-385972 Disclaimer: _I_ don't know what I said, much less my employer.
cmcmanis%pepper@Sun.COM (Chuck McManis) (07/26/89)
In article <784@bnr-fos.UUCP> protcoop@leibniz.uucp () writes:
->extern struct Remember *resources;
->tgad = AllocRemember( resources, sizeof(struct Gadget), MEMF_CHIP );
->extern struct Remember *resources;
-> FreeRemember( resources, TRUE );
AllocRemember and FreeRemember take **Remember structure pointers
so your calls should read AllocRemember(&resources,...) and
FreeRemember(&resources,...)
--Chuck McManis
uucp: {anywhere}!sun!cmcmanis BIX: cmcmanis ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.
"A most excellent barbarian ... Genghis Kahn!"
cmcmanis%pepper@Sun.COM (Chuck McManis) (07/26/89)
Also this same feature is the cause of much low memory stomping. Essentially, when used in correctly, these routines use location 0 for their pointer storage. Some fun no? --Chuck McManis uucp: {anywhere}!sun!cmcmanis BIX: cmcmanis ARPAnet: cmcmanis@sun.com These opinions are my own and no one elses, but you knew that didn't you. "A most excellent barbarian ... Genghis Kahn!"