Summary: malloc and GlobalAlloc execution caused es register to change to 0000
Keywords: memory allocation
Message-ID: <1992Jul31.024020.18529@iti.gov.sg>
Date: 31 Jul 92 02:40:20 GMT
Sender: news@iti.gov.sg (News Admin)
Organization: Information Technology Institute, National Computer Board, S'pore
Lines: 21
I'm trying to port some UNIX codes that are written for TIFF i/o (including compression and decompression routines) over to the PC environment to run under Windows using Borland C version 3.0.
I try not to change anything except throwing #ifdef statements to handle environment-specific features. All functions are changed to ANSI C functions, like fopen, fread, fwrite, etc.
Where the memory allocation function is concern, I #undef malloc if WINDOWS is defined and #define it to my own function where I use GlobalAlloc and GlobalLock while returning a LPSTR. I also maintain the handles to the global memory (HANDLE hGMem) that is returned from GlobalAlloc in a simple list which associates the hGMem with the pointer returned from GlobalLock.
When I use Borland's TDW to trace the code and examine the registers, I noticed that the es register changed some value like "es: 2D2F" to "es: 0000" when the GlobalAlloc statement is executed. This did not crash me out immediately but caused some code to fail later (Exception 13 code 0) whenever the es register is used.
Does anyone have had a similar experience before? What could be the problem? Is there a better/easier way to port memory allocation functions to Windows? I understand that malloc translate to LocalAlloc with LMEM_FIXED under Windows, which is why I'm using the above method- I need to allocate fairly big chunks. I need help urgently. Thanks.
------------- -----------------------------
LEE TEE CHONG Internet: teechong@iti.gov.sg
Computer and Communications Lab Bitnet : TEECHONG@ITIVAX
Information Technology Institute Tel (O) :(65)-7720955
National Computer Board -----------------------------
71, Science Park Drive, Singapore (0511) -----------------------------
--
------------- -----------------------------
LEE TEE CHONG Internet: teechong@iti.gov.sg
Computer and Communications Lab Bitnet : TEECHONG@ITIVAX
Information Technology Institute Tel (O) :(65)-7720955