adaptiveMalloc top-level constant

Allocator const adaptiveMalloc

A non-zero-initializing allocator that compile away to malloc in release builds.

  • In debug and profile builds, this allocator records allocation metadata when leak tracking is enabled. It integrates with the leak tracker to record allocation metadata so that native memory leaks can be detected and reported.
  • In release builds, it aliases directly to malloc with zero runtime overhead.

Platform behavior:

  • Windows: uses CoTaskMemAlloc / CoTaskMemFree
  • POSIX: uses malloc / free

Prefer this over adaptiveCalloc only when the native API you are calling fully overwrites the allocated buffer and initialization overhead is measurable. Otherwise, adaptiveCalloc is safer because it guarantees zero-initialized memory.

Use diagnosticMalloc instead if you need leak tracking to remain active in release builds.

Implementation

const Allocator adaptiveMalloc = isReleaseMode ? malloc : diagnosticMalloc;