KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q58933: Cannot Allocate More Than 64K with Calloc()

Article: Q58933
Product(s): See article
Version(s): 5.10   | 5.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | s_quickc s_quickasm | mspl13_c
Last Modified: 8-MAR-1990

Although calloc() takes two unsigned integers as parameters, it does
not allocate more than 64K. Calloc() determines the size you are
attempting to allocate by multiplying the two arguments. If the size
is greater than 64K, it will return NULL.

The confusion typically arises because, with malloc(), it is
impossible to ask for more than 64K due to the size of the argument
malloc() takes. Malloc() takes an unsigned int as an argument;
therefore, the largest number you can pass it cannot be greater than
64K. This is not the case with calloc() -- so one might make the
assumption that you COULD allocate more than 64K with calloc(). This
is simply not the case.

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.