Find size of segments in a seglist?

7 posts / 0 new
Last post
ChrisH
ChrisH's picture
Offline
Last seen: 4 years 3 months ago
Joined: 2010-12-07 20:22
Find size of segments in a seglist?

Is it possible to find the size (in bytes) of a segment in a seglist? The seglist would come from LoadSeg(), but might contain 68k & other non-OS4-native segments.

(I am a total novice regarding seglists, but I gather you can walk the list by treating the top of the segment as a pointer.)

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
On 68k the seglist looks like

On 68k the seglist looks like this:

ULONG size; /* size in longwords, i.e. divided by 4 */
BPTR next; /* BPTR to next segment. Multiply by 4 to get CPTR (use BADDR() macro) */
ULONG data[n]; /* contents of segment */

LoadSeg() returns a BPTR to "next". The "next" pointer also points to the "next" field of the next segment (or 0 if this one is the last one).

For OS4 see struct PseudoSegList in dos/dosextens.h. The comments say that it has a size field before it just like the 68k seglist.

ChrisH
ChrisH's picture
Offline
Last seen: 4 years 3 months ago
Joined: 2010-12-07 20:22
Thanks! So if I treat a

Thanks! So if I treat a segment as an array of "long", where "next" is index 0, then the size is at index "-1", right?


Author of the PortablE programming language.

I love using Amiga OS4.1 on my X1000 & Sam440 :-D

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
Should be unsigned long, but

Should be unsigned long, but yes, that's right. Note that the size is given in number of ULONGs, not in number of bytes.

ChrisH
ChrisH's picture
Offline
Last seen: 4 years 3 months ago
Joined: 2010-12-07 20:22
Quote:Note that the size is

Note that the size is given in number of ULONGs, not in number of bytes.

Ah, thanks, I would have got that wrong.


Author of the PortablE programming language.

I love using Amiga OS4.1 on my X1000 & Sam440 :-D

amiganaut
amiganaut's picture
Offline
Last seen: 9 years 12 months ago
Joined: 2014-11-22 00:51
@thomas: Note that the size

@thomas:


Note that the size is given in number of ULONGs, not in number of bytes.

Are you sure that this information is correct? AFAICS the size is in bytes and not in ULONGs under OS3.

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
Are you sure that this

Are you sure that this information is correct?

No, I am not ;-)

Looking into another program from me it seems you are right, the length is in bytes.

Log in or register to post comments