TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Frank Adam
from: Adam Fitzpatrick
date: 1996-12-05 01:03:26
subject: Auto string-length d

Quoting Frank Adam to Michael Stapleton:

[snip]

MS>Interesting...  I wonder what it'd do on my Amiga...  :) I've
MS>seen PC programmers talking about "the heap" and I guess it's
MS>where malloc() gets its memory, but the rest is a mystery.
MS>Memory allocation is more anarchic over here.  :)

FA>For instance in asm you would go straight to DOS
FA>and grab a chunk, but it's my belief that a routine in the Borland RTL
FA>intercepts all alloc calls and builds an internal memory table, so non
FA>standard stuff like  heapwalk() can function. 
 
MS>There are several varieties of memory allocation in the Amiga OS, as
MS>well as the standard allocation functions provided by the compiler.
MS>If I use malloc() or AllocVec(), then I can find the blocksize at a
MS>negative offset from the returned pointer.  OTOH, if I use

FA>Yeah, i though i could too, but when i used a different compiler it
FA>didn't work.(Pacific to be exact.)  
 
MS>called AllocRemember, which returns size & other information via a
MS>structure double pointer.

FA>Hm, DOS must be a bit more senile. 

FA>I've read/tested the DOS memory functions now a few(hundred?) times,
FA>but i can't find any reliable way of finding out the size. After it
FA>allocates it just returns the number of blocks and the size is history
FA>from there on.

The size is what was in BX before you made the MOV AH,48h; INT 21h call.
It's also stored in the MCB.

FA>It still bugs me, there HAS TO BE a table within DOS somewhere !      

There is. I can't remember how to find the start of the table (it's
documented in Ralf Brown's interrupt list), but the 16 bytes at (q-1):0
(where q is the segment returned by the INT 21h call) are called the
Memory Control Block. They tell you about the block of memory. The byte
at q-1:0 is either 'M' or 'Z' (Z indicates it's the last block in memory,
M means there's another in the chain), the word at q-1:1 is the segment
of the PSP of the program that owns the block, q-1:3 is the number of
paragraphs (16 byte blocks) in the block (if this number is X, the next
block (if there is one) has its MCB at (q+X):0), and the 8 bytes at q-1:8
are supposed to be the name of the program to which the block was
allocated.

... (A)bort, (R)etry, (H)ug Teddy bear and cry?
--- FMail/Win32 1.22
* Origin: Power BBS - +61-2-858-4114 - Files/Games/EchoMail/Internet (3:711/953)
SEEN-BY: 633/267 270
@PATH: 711/953 410 808 50/99 635/728 633/267

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™.