Skip to content

Static override of malloc-like functions on Windows #1074

Open
@Noxybot

Description

@Noxybot

Hi @daanx, just a general question - why mimalloc doesn't provide overrides for malloc-like function on Windows when built as an object file.
Specifically, this code block:

#elif defined(_MSC_VER)
  // cannot override malloc unless using a dll.
  // we just override new/delete which does work in a static library.
#else

Could override publicly available functions from ucrt/corecrt_malloc.h, like

_Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size)
_ACRTIMP _CRTALLOCATOR _CRT_JIT_INTRINSIC _CRTRESTRICT _CRT_HYBRIDPATCHABLE
void* __cdecl malloc(
    _In_ _CRT_GUARDOVERFLOW size_t _Size
    )
{
    return mi_malloc(_Size);
}

Any caveats in such approach? It seems to work just fine in our scenario. (When we link mimalloc as an object file + using static CRT)
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions