| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | free() |
G'Day David,
-=> Quoting David Nugent to Frank Adam <=-
> What i would like to know now is, if the allocated size of the array
> ptr points at can be determined in some way.
DN> Not by any documented means. The RTL or at least the
DN> operating system almost certainly would need to track the
DN> existing size of allocated memory blocks in order to
DN> implement realloc(), but the C programmer has no direct
DN> access to that information. It is ultimately up to you to
DN> keep track of it yourself.
Yep, someone will just have to find that location/table or whatever :)
There must be a table somewhere holding a handle,address and bytes.
I went through the interrupt list and no banana, perhaps it's the RTL,
wonder if i can walk through and search the whole memory without crashing
should be able to..I think i'll try that.
I've noticed that OS' like to use negative offsets here or there, perhaps
it tacks a few bytes in front of each memory block.
> I'm in the process of putting all my library function neatly together,
> and i would love to make some functions capable of determining whether a
> reallocation is necessary or not, and not rely on the programmer taking
> care of it.
DN> Write a front-end to malloc() to do it for you. I often use such a
DN> wrapper since it helps in debugging as well - I've included a
DN> variation of it below. You can detect heap corruption
DN> (boundary overwrite), attempting to free pointers which
DN> were not allocated from the heap to begin with, blocks that
DN> have already been freed, and you can issue diagnostics on
DN> where the function was called from and so forth.
-- cut & paste to clipboard --
Thanks, this'll ruin a whole afternoon for me to work out :)
That imaginary memtable still bugs me though, if it's in there i want it.
L8r Frank (fadam{at}ozemail.com.au).
___ Blue Wave/DOS v2.21
--- Maximus 3.01
* Origin: The Software Parlour (3:635/544)SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 727 711/401 409 410 413 SEEN-BY: 711/430 808 809 932 934 712/515 713/888 714/906 800/1 @PATH: 635/544 50/99 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.