Skip to main content

Questions tagged [memory-management]

For questions related to managing memory in programming languages, whether manually or automatically.

Filter by
Sorted by
Tagged with
4 votes
0 answers
93 views

Idiomatic memory allocation and garbage collection in LLVM

I am working on a new backend for a programming language using LLVM IR. This language makes a distinction between basic values and pointers to nodes on the heap, and uses a copying collector for ...
user65560's user avatar
  • 141
13 votes
3 answers
3k views

A kind of "weak reference" which keeps the object alive, as long as there is otherwise-unused memory

Modern operating systems usually use some of the main memory for caching files, as loading those files from the cache will be faster than loading them from disk; but this memory can be reclaimed by ...
kaya3's user avatar
  • 20.8k
8 votes
2 answers
625 views

Analysis of methods to ensure memory safety

Overview Ensuring memory safety is a core facet of modern programming language design. Memory safety can be guaranteed in many different ways. For the purposes of this question, I am defining memory ...
Wesley Jones's user avatar
5 votes
1 answer
220 views

Alternatives to tracing GC for dynamically-typed languages

What are some alternatives to tracing GC for dynamically-typed languages? I've been interested in dynamically typed languages with predictable behavior since learning about lua in the NetBSD kernel. ...
Greg Nisbet's user avatar
4 votes
2 answers
626 views

Are there actual languages using fat pointers to store types?

In the normal implementations of C++, while not guaranteed by the standard, there is a vtable pointer as the header of every inherited class that needs a vtable pointer. There will be multiple vtable ...
user23013's user avatar
  • 2,840
3 votes
0 answers
257 views

Is there a downside to using offsets instead of raw pointers in a virtual machine?

Say I'm designing a virtual machine for a bytecode compiler/interpreter, using C as the implementation language. Some kind of “tagged” representation of values is simplest for this language, where ...
texdr.aft's user avatar
  • 313
3 votes
6 answers
544 views

Are there languages or compilers having optimizations to deallocate variables early?

In a scope that defines two variables a and b, the code firstly does things only on a. Then <...
user23013's user avatar
  • 2,840
6 votes
4 answers
888 views

If garbage collection always sacrifice performance in multi-threaded languages, then how do some languages approch this problem?

Mark-and-Sweep garbage collection need to work over the graph of all objects in the process, and would stall threads to make the operation safe with regard to threads. I can think of no way to work ...
DannyNiu's user avatar
  • 287
22 votes
2 answers
4k views

To box or not to box? (how to determine if a value can be more efficiently passed by value or by reference)

I want to remove explicit addressing from my type system. In low level languages like C or Rust, you always have a choice whether to store some data by value or by reference. There are some advantages ...
mousetail 'he-him''s user avatar
16 votes
3 answers
575 views

What was the rationale for making realloc(ptr, 0) have UB in C23

This is the first breaking change that C made, which was making realloc(ptr, 0) have UB instead of being roughly equivalent to ...
user1345541's user avatar
2 votes
1 answer
283 views

Are there languages making addresses to have other significant meaning?

Some examples: To support checking whether an object is of a subclass of a specific class in constant time, in a language using single inheritance, the compiler could arrange the vtables of classes ...
user23013's user avatar
  • 2,840
16 votes
6 answers
4k views

Possible to mix garbage collection and manual memory management?

Do you think it is possible to have a language that uses garbage collection (GC) by default, but allows you take more control with manual memory management like C++ or Rust, in areas of the software ...
Rob N's user avatar
  • 1,115
3 votes
1 answer
412 views

X86-64 Assembly for Recursive Functions

A compiler I'm writing generates the following x86-64 assembly (AT&T syntax) for a recursive factorial function. I convert the assembly into an ELF executable using ...
Veera Sivarajan's user avatar
12 votes
2 answers
688 views

Why did Objective-C remove `NSZone`?

NSZone is a type representing a memory allocation. NSObject implements the allocWithZone: ...
Bbrk24's user avatar
  • 9,407
6 votes
3 answers
878 views

Why might a language avoid reallocation?

In Java, the size of arrays are immutable. However, to my understanding, they are still allocated on the heap, because Java allocates almost everything on the heap. Even then, Java arrays are still ...
CPlus's user avatar
  • 9,143
3 votes
1 answer
282 views

Memory layout from a native class

I think there are languages where most of the standard library is written in themselves, however with most things marked as native or ...
Hydroper's user avatar
  • 1,027
6 votes
5 answers
640 views

Approaches for implementing weak references

How can weak references (weakrefs) be implemented, and how do the different approaches compare? The most important considerations for implementing weakrefs are: Safety ─ a weakref shouldn't allow ...
kaya3's user avatar
  • 20.8k
15 votes
2 answers
644 views

Could ownership be inferred?

Rust famously has the concept of ownership vs. borrowing as part of its type system. This allows some level of automatic memory management ─ that is, heap allocations are freed when their owner goes ...
kaya3's user avatar
  • 20.8k
13 votes
3 answers
2k views

Is it possible to extend C to have the Rust concept of ownership for memory safety?

Rust has a number of memory safety features. Is it possible to extend or enhance C or C++ to also provide similar memory safety features instead of using workarounds such as the Valgrind tool suite?
James Risner's user avatar