9
votes

Are there any languages other than C and C++ that can be used explicitly without dynamic memory allocation (i.e. heap) features. In some mission critical embedded systems, use of the heap is prohibited to eliminate memory leak problems for software that may run continuously for many years. Some special purpose compilers also explicitly disable new and malloc to enforce this practice.

I've looked at some of the functional languages, namely Timber and Erlang for their embedded emphasis, but both seem to use heaps with a garbage collector. OCaml and Haskell also use garbage collectors despite static typing, and obviously Python, Ruby, and other dynamically typed languages rely heavily on garbage collection and heap space.

  • Do any high-level languages support this requirement of not dynamically allocating memory?
  • Is this even possible for compilers of functional statically typed languages to do so given their language semantics?
2
I would consider C++ templates very high level (for instance, it's possible to compile Logic in templates). But it's a lot more difficult than other languages to learn. - CapelliC
Do you consider Forth as being a high-level language? - Sylvain Leroux
I would like to find something more "high-level" than Forth. I am aware that C++ templates support all kinds of crazy capabilities, but I've always felt template metaprogramming is more a discovery hack with the language than an intentional use case. - kgraney
Dynamic allocation is a bit of a mis-nomer. Ie, just banning malloc and new is not enough. They are just other functions. With Java or more specifically garbage collection, you can have un-intentional references. Something like alloca() allows run-time allocation from a stack as do C/C++ Variable length arrays. Even this may be prohibited as your definition of dynamic memory maybe different than others. I believe you want something that pre-determines maximum memory use at compile time. - artless noise
FragmentPoolC and at U-Utah. Another take relates to time at tlsf.baisoku.org - artless noise

2 Answers

1
votes

You could have a look at ADA. I've been using ADA83 on embedded platforms a few years ago. It didn't require dynamic allocation at all, and it is as high-level as C is (it's even better than C, in my own opinion). The problem, of course, is to get an ADA compiler for your platform. Maybe GNAT would work for you.

-4
votes

A program in essence is data structures and its manipulation by using suitable algorithms. Data has to be held in memory somewhere. It can either be in global, stack or heap memory.

Just because heap is not used is no guarantee that global or stack will not get corrupted by bad code.

If a system is well designed, then it should have all the necessary resources needed, i.e. cpu, memory, os, bandwidth, power, cooling, etc., to perform the desired function.

One can implement by managing global memory instead of heap memory but that would render lot of the libraries that use pointers useless.

I think the best approach is to keep it simple, get lots of dynamic visibility into the system when running/debugging, and make sure that unit tests, code coverage tests and system boundary tests are performed thoroughly before declaring fit for deployment.

If it is well designed, well engineered and well tested then it should do everything well that it is supposed to do and not do anything it is not supposed to do.

There are compiled languages that don't have pointers, e.g. Fortran, but I don't know of any embedded systems that uses Fortran exclusively to implement a system.