Announcement

Collapse
No announcement yet.

HeapAlloc

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • HeapAlloc

    I am trying to understand the heap, and the allocation deallocation and related, but all examples I seem to find use examples such as
    FUNCTION = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, MAX( 16, nSize + 1))
    Which is the best one I have seen cause to my knowledge "MAX( 16, nSize + 1))" would mean "To choose which is greater? 16? or SIZEOF(datatype)"

    The problem being, I do NOT like hardcoded values with no explanation of what the value means. So I have to ask
    • Why 16? (some minimum value? or what is the real equates?)
    • nSize (obvious from examples is the size) but why the add one? (I can only guess for an added null, or a zero-vs-one based concept or something

    I am sure its in the docs somewhere, but either I am having a CNDS or just not understanding, so hopefully someone can explain it???
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    I would bet dollars to donuts that was some 'C' programmer covering a body part against attempting to allocate SIZEOF(something) which was zero and he was too lazy to check the return.

    Correct use is
    Code:
    pData = HeapAlloc (hHEap, flags, size).
    IF ISFALSE pData THEN 
        E = GetLastError  
        yadda yadda 
    ELSE
        CONTINUE       ' <<< a great verb, available in COBOL. 
                            ' for all those places where "something" is required but 
                            ' you really don't need do anything. 
    END IF
    FWIW, these are usable...
    malloc, realloc, free for PB/Win32 September 20, 2002

    Think of these as HeapAlloc with a better user interface.

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Oh, wait a minute, I can see it already.... some ASM-head is going to post...
      Code:
      MACRO CONTINUE  = !NOP
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment

      Working...
      X