Some years ago I wrote a diary program, which does everything I want, but has a problem. If I save an entry it usually - but not always - succeeds, though the program will often terminate or hang-up afterwards. If I save another entry, termination or hanging up was almost guaranteed. I have been over the file save routine I don't know how many times, but couldn't find a problem. Diary entries are made in a TextEdit style box.
Find length of entry
Allocate space using MemAlloc
Read the entry into the space
Save the entry to file
Free the space using MemAlloc free.
A week or so ago I got the bright idea. Instead of using MemAlloc, I set aside a block of memory using DIM, so the routine is identical to the above apart from the calls to MemAlloc. After years of frustration, the program now works perfectly.
If anyone with experience of MemAlloc can suggest what the problem might have been, I would be grateful and, hopefully, wiser.
MemAlloc
-
jgharston
- Posts: 58
- Joined: Thu 05 Apr 2018, 14:08
Re: MemAlloc
If using memory from the heap (claimed with DIM) works, then you could try using the Heap MAlloc library and malloc() memory from the heap: MAlloc
If that doesn't work, it could be that the way you're using malloc'd memory is at fault.
If it works, it could be that the system malloc-er is working but you're accessing the memory given to you wrongly.
If that doesn't work, it could be that the way you're using malloc'd memory is at fault.
If it works, it could be that the system malloc-er is working but you're accessing the memory given to you wrongly.
-
KenDown
- Posts: 330
- Joined: Wed 04 Apr 2018, 06:36
Re: MemAlloc
Thanks for your reply and advice. I was simply using SYS"GlobalAlloc",0,L%+1TOF% where L% is the length of the required data entry and F% is a LOCAL variable declared at the beginning of the procedure.
To get the program to work I have simply deleted all the "GlobalAlloc" calls and instead of F% I now have a DIM-ed space. That memory is accessed in exactly the same way as before, so I don't think that I'm accessing it wrongly.
To get the program to work I have simply deleted all the "GlobalAlloc" calls and instead of F% I now have a DIM-ed space. That memory is accessed in exactly the same way as before, so I don't think that I'm accessing it wrongly.