r/cprogramming • • Sep 14 '26

No idea if my arena allocator works 😭

I built a small arena allocator in C called PhaseAlloc. The problem is i have no idea if it works on other computers/platforms other than my own 😭

It's now at v1.1.0, with tests, benchmarks, dynamic growth, alignment, and memory stats.

I'd appreciate any feedback or criticism from people who know C/systems programming.

Its downloadable here, so pls help me out 🙏:

https://github.com/dharsanap20/PhaseAlloc

0 Upvotes

20 comments sorted by

2

u/nukestar101 Sep 14 '26

Did not dive deep but what's the use of 'phasealloc_internal.h' ? Why can't the content of this header be in 'phasealloc.c' ? Phase chunk is private and has no business exposing it to public.

Make use of static for the functions not exposed to public

1

u/flyingron Sep 14 '26

It's not exposed to the public. It's hidden in the soruce directory. Only phasealloc.h appears to be in a "public" space.

1

u/Rare-Anything6577 Sep 16 '26

He asked about the internal header being in the C file (already not exposed to the public), not the header file.

1

u/flyingron Sep 16 '26

And the answer is the header is not exposed to the public either and sometimes it's convenient splitting things up.

1

u/nukestar101 Sep 16 '26

When you package things up. You ship the binary and header separately (for dev packages) and headers is how to interpret the underlying binary, by putting things in header the user now has the memory interpretation of the binary which is not a good practice.

0

u/flyingron Sep 16 '26

Says you. But it was in the source directory, so it's just as exposed as any of the C files. It wasn't in the distributable include directory.

I'll bet you, I've distributed more code in 49 years of C development than you EVER will.

8

u/zhivago Sep 14 '26

parse_true has an error.

What does

    if (strncmp(*input, "true", 4) != 0)

do if *input holds "truely"?

2

u/SheikHunt Sep 14 '26

One of the first mistakes I ever made in C.

1

u/foxsimile Sep 15 '26

Truely is not truly a word.

3

u/flyingron Sep 15 '26

So, there's nothing to constrain people from inputing non-words either.

-1

u/foxsimile Sep 15 '26

Inputting

2

u/zhivago Sep 15 '26

What better to illustrate an error?

1

u/lehmagavan Sep 14 '26

How much faster is your arena compared to malloc? Im curious cause Im building my own arena implementation at the moment

1

u/DreadSpidey Sep 15 '26

My allocator Phasealloc was about 27–36% faster than malloc/free on the allocation benchmarks, depending on the workload.

For the JSON workloads, it was around 60–73% faster.

If you have the time can you check out the allocator by cloning or downloading, because i want to see if it works on other platforms lol

1

u/lehmagavan Sep 15 '26

It appears you have bunch of missing #include's in /tests

1

u/DreadSpidey Sep 16 '26

Im not sure i know what you mean. It looks and works good

1

u/lehmagavan Sep 16 '26

They don't compile due to incorrect paths or undefined references.

1

u/lehmagavan Sep 16 '26

My fault, sorry. Forget what I said.

1

u/DreadSpidey Sep 15 '26

Ok, check the repo's README again, i just updated it to include all the benchmarks