Get the latest tech news

Tip of the day #2: A safer arena allocator


Published on 2024-10-29 Discussions: /r/programming, /r/cprogramming The most transformative action you can do to dramatically improve your code in a programming language where you are in control of the memory is: to use arenas. Much has been written about arenas (1, 2).

Very simple, just ask the OS to give us a region of virtual memory and off we go (on Windows, the system call is named differently but is equivalent). Replace all direct array and pointer accesses with macros that check bounds (like most modern programming languages) Tweak how the arena is created to make it safer. Also, reusing a previously allocated-then-freed object with a different type, without zero-initializing it, can leak secrets or information about the state of the program, to an attacker.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Day

Day

Photo of tip

tip

Related news:

News photo

October 30 – Reflections on the Day the Earth Moved for H5N1

News photo

Used tire-based solar desalination tech makes 3.67 liters of drinking water daily | The device generated 3.67 liters of fresh water each day during the test in Halifax Harbour.

News photo

Elite School Will Offer a Day Off for Students Distressed by Election