Thread View: comp.os.msdos.programmer
2 messages
2 total messages
Started by Brian Parkinson
Tue, 12 Jan 1993 13:30
Help on Memory Manager
Author: Brian Parkinson
Date: Tue, 12 Jan 1993 13:30
Date: Tue, 12 Jan 1993 13:30
34 lines
1539 bytes
1539 bytes
A general question (re memory management under DOS). If I allocate a pointer to 64K in Borland C. unsigned char *ptr = farmalloc(0xFFFF); The pointer has some segment, and the offset is always 4 (four). This means that the last few bytes of data are actually in the NEXT segment !! If the pointer is declared to be far, then these bytes roll to the bottom of the same segment. My question is twofold : (1) What does DOS do with these 4 extra bytes - are they used by the memory manager of DOS (or, in an even weirder scenario, is this a quirk of Borland C, and would not appear in Microsoft C) ??? (2) I need to have a 64K (EXACTLY) byte memory block in an application, and would like to be aligned from the base of the segment (i.e. an offset of 0 (zero) not 4 (four)), so if I just say "ptr-=4", the pointer will now be at the base of the segment, but..... is this inviting disaster ??? Does someone out there know the answers to this (what I consider to be a) quirk ? -- What's the point in callin' shots Brian Parkinson This cue ain't straight in line <parki@csri.toronto.edu.ca> The cue-ball's made of styrofoam And no-one's got the time
Re: Help on Memory Manager
Author: Walter Bright
Date: Sat, 23 Jan 1993 23:38
Date: Sat, 23 Jan 1993 23:38
20 lines
1704 bytes
1704 bytes
In article <1993Jan18.185050.4937@proto.com> joe@proto.com (Joe Huffman) writes: /bright@nazgul.UUCP (Walter Bright) writes: />In article <1993Jan12.083016.4726@jarvis.csri.toronto.edu> parki@csri.toronto.edu (Brian Parkinson) writes: />/(2) I need to have a 64K (EXACTLY) byte memory block in an />/application, and would like to be aligned from the base of />/the segment (i.e. an offset of 0 (zero) not 4 (four)), so />/if I just say "ptr-=4", the pointer will now be at the base />/of the segment, but..... is this inviting disaster ??? />Yes, you are inviting disaster doing this. /You can save the 4 bytes of data at the offset 'ptr - 4' then restore /it before you free it. IMHO this would result in a slight risk of /disaster, rather than 'inviting disaster'. Assuming, of course, that those 4 bytes do not form a link in some linked list used by the Borland library routines, and you don't have any intervening calls to such routines. If you want to be sure, you'll have to look at the Borland library source. Otherwise, call DOS directly to do your own memory allocation. In any case, if you use those 4 bytes you will be relying on undocumented behavior which should be avoided whenever a practical alternative exists.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads