Memory Management in the Win32 API

DB Library for C

DB Library for C

Memory Management in the Win32 API

The 32-bit linear virtual memory address space available to processes in the Microsoft® Win32® API makes memory management simpler and cleaner. (This applies to DB-Library programming as well as to all other programming for the Win32 API.)

Although the memory management functions (GlobalAlloc, LocalAlloc, and so on) in the Microsoft Windows® operating system are supported in the Win32 API, consider using the C run-time functions malloc and free to perform dynamic memory management when you develop applications to run with the Win32 API. In addition to the standard memory management functions (Global and Local, C run-time support), the Win32 API also provides heap and virtual memory management functions for applications that require specialized memory management.

Two specific areas of DB-Library programming can take advantage of the ability to address greater than 64 KB of data:

  • Processing of text and image data.

    There are many uses for Microsoft SQL Server™ text and image data types. All require manipulation of text and image data, and the ability to transfer data between the application and SQL Server. The ability to address large chunks of memory can make this easier. Because it is possible to address up to 2 gigabytes (GB) of user memory in an application for the Win32 API, you can develop text/image handling functions that transfer text/image data in a single operation instead of transferring data chunks less than 64 KB. (Note, however, that waiting for 2 GB of data to transfer can take considerable time.)

  • Row buffering.

    In DB-Library for Microsoft MS-DOS® and Windows, you are constrained because DB-Library cannot handle more that 64 KB of data at a time, including memory allocated for row buffering. This value is further reduced by overhead taken up by data structures, variables, and so on. In the Win32 API, it is possible to use DBSETOPT(DBBUFFER,...) to enable row buffering for data sets greater than 64 KB.