Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it feasible for a general purpose programming language to not have a heap? [closed]

I'm looking into creating a programming language. What I'm wondering is, in a language that contains a reference-like construct, is it feasible to not have a new/malloc operator? That is, all variables are stored either on the stack somewhere or are statically allocated.

The idea is that you get better type safety, as well as "free garbage collection" without actually having a garbage collector.

I'm not familiar with too many scripting languages, so if one already does this, feel free to point it out.

(Dynamic / unknown size data structures would be handled by a dynamic list structure, which would be handled (obviously) on the heap, behind the user's back.)

like image 374
Dan Avatar asked Dec 15 '11 20:12

Dan


People also ask

Do all programming languages use heap?

Different languages use the stack and the heap differently; C and C++ allocate to the stack automatically, and you as the developer manually have to allocate and deallocate from the heap, where more modern languages such as Go and Java allocate to both the stack and the heap automatically, and have a garbage collector ...

Why is heap memory necessary?

You should use heap when you require to allocate a large block of memory. For example, you want to create a large size array or big structure to keep that variable around a long time then you should allocate it on the heap.

What is not a general-purpose programming language?

The opposite of a general-purpose programming language is a domain-specific programming language, which is designed to be used within a specific area, for example, querying databases. For example, SQL was designed for querying databases.

When should you use the heap?

Use it whenever you need quick access to the largest (or smallest) item, because that item will always be the first element in the array or at the root of the tree. However, the remainder of the array is kept partially unsorted. Thus, instant access is only possible to the largest (smallest) item.


2 Answers

Fortran was always quite a "general purpose" language, but it had no support for any kind of a dynamic memory allocation out of the box.

A usual practice was to allocate a big array statically and simulate your own memory management on top of it.

If a way to get rid of both GC and a manual memory management is what you're looking for, then region analysis can help, but only in few specific cases.

like image 162
SK-logic Avatar answered Nov 15 '22 07:11

SK-logic


Region-based memory management was one approach for not having a heap managed in the traditional sense. This manifested in languages like FX and MLKit.

like image 41
Sam Tobin-Hochstadt Avatar answered Nov 15 '22 06:11

Sam Tobin-Hochstadt