I've always put languages into 2 types... ones that let you refer to "undefined" (uninitialized, freed, etc.) memory, such as C, C++, COBOL (?), Assembly, etc. and ones that you can't such as Java, Perl, C#, and Basic. Is there a "computer science" term for this distinction? While we're at it, is there a computer science term to what I call "undefined memory"?
views:
60answers:
4Can you define "refer to"? If you simply mean that you can get at garbage memory without warnings or errors, I don't think that there is really a formal distinction there. The distinction I can think of that might be pertinent is "High Level" and "Low Level". High Level (further abstracted from assembly) languages like Java and C# generally abstract away the ability to start referencing garbage for obvious reasons. Lower level (close to assembly) languages don't simply for the sake of leaving it open to the developer (this is similar to memory management). Undefined memory is normally referred to as unused, garbage, or freed memory.
Pointer Safety.
I apologize for not being able to attribute the original author. I know I've seen Erik Meijer mention and define it though.
Pointer safety (or memory safety) is the attribute of a program, or all programs in a particular language or other constraint, where the program cannot address memory other than that it explictly allocated and owns, or through an intermediary, such as OS.
Type safety is also such an attribute, but is generally stricter -- if something is typesafe, it's generally pointer-safe as well. In this attribute, memory is referred to as "objects" that have a type, and the program never manipulates that memory except through operations on that type. I'll leave the various conflicting definitions of type alone for now, as that can also be a big question.
These attributes apply generally, and can apply to various memory management strategies -- dynamic heap allocations, arena allocators, stacks, and 'static' or 'global' storage. It's not just about heaps.
Wikipedia on pointer safety and type safety.
You know, I've always used the term Memory Safety when discussing these topics. And I consider C/C++ "Memory Unsafe" languages. I don't actually know if this is the accepted terminology, so I'll be interested in seeing other answers.
As for terms for "undefined memory", I believe that term would be a combination of 2 other terms:
Unallocated memory: Memory which has not been set aside for use by a program.
Uninitialized memory: Memory which has been allocated, but has not been given a meaningful value by the program.