Category : C Source Code
Archive   : BCPPTECH.ZIP
Filename : TI660.ASC

 
Output of file : TI660.ASC contained in archive : BCPPTECH.ZIP







PRODUCT : Borland C++ NUMBER : 660
VERSION : All
OS : PC DOS
DATE : February 25, 1992 PAGE : 1/1

TITLE : Dynamically Allocating >64K in Windows 3.0





In Windows the pointer returned by malloc() is really a selector.
When you malloc() more than 64k, Windows will set up multiple
selectors. To use the pointer you need to increment the offset
until it reaches 0x0000 again (it always starts at 0x0000). You
then need to add a constant value to the segment (Petzold says 8
for protected mode, 0x1000 for real mode. See page 295 of
Windows 3.0 Power Programming.), which will give the next
selector! For example:

/* Must be far... huge pointers do not work */
char far *pfoo;

/* 'pfoo' points to first 64k */
pfoo = (char far *) farmalloc (1000000ul);

/* Advance to next segment */
while (FP_OFF (pfoo) != 0x0000) pfoo++;

/* Now points to second 64K */
pfoo = MK_FP (FP_SEG (pfoo) + 8, 0x0000);






























  3 Responses to “Category : C Source Code
Archive   : BCPPTECH.ZIP
Filename : TI660.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/