Skip to content

Use enif_alloc/enif_free for std::vector allocations#79

Merged
DenysGonchar merged 2 commits into
masterfrom
vector-allocator
May 14, 2026
Merged

Use enif_alloc/enif_free for std::vector allocations#79
DenysGonchar merged 2 commits into
masterfrom
vector-allocator

Conversation

@NelsonVides
Copy link
Copy Markdown
Collaborator

std::vector's default std::allocator uses malloc/free, which bypasses BEAM memory bookkeeping. Introduce a custom enif_allocator<T> that delegates to enif_alloc/enif_free so all NIF heap usage is visible to erlang:memory() and crash dumps.

Not sure who's the ideal reviewer for this so tagging a couple of guys 😉

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.99%. Comparing base (6b9481c) to head (5084897).

Files with missing lines Patch % Lines
c_src/exml.cpp 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #79      +/-   ##
==========================================
- Coverage   74.01%   73.99%   -0.02%     
==========================================
  Files           7        7              
  Lines        1189     1196       +7     
  Branches      169      171       +2     
==========================================
+ Hits          880      885       +5     
- Misses        309      311       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@kamilwaz kamilwaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 👍 I just left one small comment, but it's not mandatory.

Comment thread c_src/exml.cpp Outdated
@NelsonVides NelsonVides force-pushed the vector-allocator branch 2 times, most recently from 1d7098b to b19d790 Compare May 13, 2026 10:21
@NelsonVides NelsonVides requested a review from kamilwaz May 13, 2026 10:28
Copy link
Copy Markdown

@DenysGonchar DenysGonchar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good

NelsonVides and others added 2 commits May 14, 2026 14:55
std::vector's default std::allocator uses malloc/free, which bypasses
BEAM memory bookkeeping. Introduce a custom enif_allocator<T> that
delegates to enif_alloc/enif_free so all NIF heap usage is visible to
erlang:memory() and crash dumps.
Co-authored-by: Kamil Wąż <kamilwaz@icloud.com>
@DenysGonchar
Copy link
Copy Markdown

I rebased on top of the latest master changes just to trigger CI benchmark job

@DenysGonchar DenysGonchar merged commit 136daf1 into master May 14, 2026
5 checks passed
@DenysGonchar DenysGonchar deleted the vector-allocator branch May 14, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants