API Reference | developer.brewmp.com API Reference | developer.brewmp.com

Developer

API Reference

FUNCTION: MALLOCREC()

Brew Release
Brew MP 1.0.2
See Also
MALLOC() Helper Functions
Description
This is an alias of the MALLOC() function that is useful for avoiding typecasts. MALLOCREC() zero-initializes the block of memory to which it returns a pointer.
Params
type
[]:
A C-language type definition that is suitable for casting and taking the sizeof() function.
Prototype
  •    type *MALLOCREC(type);
    
Return
  • If successful, returns a valid pointer to a buffer of size sizeof(type) bytes.
    If failed, returns NULL.
Side Effect
  • None
Comments
Here's how it is used. Instead of like this: pMe = (struct MeStruct *)MALLOC(sizeof(struct MeStruct)); you get this: pMe = MALLOCREC(MeStruct); By placing the (dangerous) cast where the sizeof is taken, this avoids mistakes like: pMe = (struct MeStruct *)MALLOC(sizeof(struct TypoStruct)); which could cause over-allocation or a crash (depending on the size of TypoStruct). It's also a little more concise.