facebook / facebook/folly

Simulating calloc for std::vector (UninitializedMemoryHacks.h simulates malloc)

Open
#1,508 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
30.5k
Forks
5.9k
PR merge metrics
No merged PRs in 30d

Description

Hi,

UninitializedMemoryHacks.h is a great solution when one is interested to take advantage of all the functionalities of an std::vector, but using malloc instead of resize for initialization.

My question: is there a similar solution for **calloc**?

calloc is known to use some OS tricks to guarantee that the allocated memory is 0-initialized, but without actually accessing it.

Ideally, I'd like to be able to use something like the following line for initializing a vector with 0's:

folly::initWith0s(v, sz);

Thanks,
Alex.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.