Tag Info

Hot answers tagged

108

You really can't make blanket statements about appropriate way to use all GC implementations. They vary wildly. So I'll speak to the .NET one which you originally referred to. You must know the behaviour of the GC pretty intimately to do this with any logic or reason. The only advice on collection I can give is: Never do it. If you truly know the ...


91

In the case of a CPU cache, it is faster because it's on the same die as the processor. In other words, the requested data doesn't have to be bussed over to the processor; it's already there. In the case of the cache on a hard drive, it's faster because it's in solid state memory, and not still on the rotating platters. In the case of the cache on a web ...


60

Sadly, nobody there elaborates on what are such cases. I'll give some examples. All in all it is rare that forcing a GC is a good idea but it can be totally worth it. This answer is from my experience with .NET and GC literature. It should generalize well to other platforms (at least those that have a significant GC). Benchmarks of various kinds. You ...


56

The basic difference between stack and heap is the life cycle of the values. Stack values only exist within the scope of the function they are created in. Once it returns, they are discarded. Heap values however exist on the heap. They are created at some point in time, and destructed at another (either by GC or manually, depending on the language/runtime). ...


50

Modern C++ makes you not worry about memory management until you have to, that is until you need to organize your memory by hand, mostly for optimization purpose, or if the context forces you to do it (think big-constraints hardware). I've written whole games without manipulating raw memory, only worriing about using containers that are the right tool for ...


47

Space software is not arcane magic. You are still using 0's and 1's, not 1's and 3's. So there’s probably no wow factor involved in describing what goes into developing software. Some slight differences that come to mind at the moment are: Extremely process oriented. Space software will always have both software and hardware watchdog timers. Every space ...


43

They're not quite the same. The registers are the places where the values that the CPU is actually working on are located. The CPU design is such that it is only able to actually modify or otherwise act on a value when it is in a register. So registers can work logic, whereas memory (including cache) can only hold values the CPU reads from and writes to. ...


40

In your example myApple has the special value null (typically all zero bits), and so is referencing nothing. The object that it originally referred to is now lost on the heap. There is no way to retrieve its location. This is known as a memory leak on systems without garbage collection. If you originally set 1000 references to null, then you have space for ...


33

I can see a DOS programmer fiddling away and crashing the entire OS when he made a mistake. Yeah, that's pretty much what happened. On most systems that had memory maps, location 0 was marked invalid, so that null pointers could be easily detected, because that was the most common case. But there were lots of other cases, and they caused havoc. At ...


29

Heaps are bad at fast memory allocation and deallocation. If you want to grab many tiny amounts of memory for a limited duration, a heap is not your best choice. A stack, with its super-simple allocation / deallocation algorithm, naturally excels at this (even more so if it is built into the hardware), which is why people use it for things like passing ...


28

It is faster because both it is closer and because it is SRAM not DRAM. SRAM is and can be considerably faster than DRAM the values are kept statically (the S in SRAM) so they don't have to be refreshed which takes away cycles. DRAM is dynamic, like tiny rechargeable batteries, you have to regularly recharge the ones so they don't drain away and become ...


27

As a general principle, a garbage collector will collect when it runs into "memory pressure", and it's considered a good idea to not have it collect at other times because you could cause performance problems or even noticeable pauses in your program's execution. And in fact, the first point is dependent on the second: for a generational garbage collector, ...


26

I just stumbled into your interesting question. I was at Instrumentation Lab during Apollo, and again later when it was called Draper Lab during the "cold war". For the Apollo guidance computer, core was used for RAM, and a special braided core was used for ROM. The machine itself was made entirely out of NOR gates and was clocked quite slow, for ...


26

Memory management is used to scare children, but it is only one kind of resource that a programmer has to look after. Think file handles, network connections, other resources that you obtain from the OS. The languages that support garbage collection usually not only ignore the existence of these resources, but they also make it harder to handle these ...


23

Back in my day, we didn't have memory protection and all that snazzy business! We used printf to determine where we were in the program, and we liked it! Though in all seriousness, it usually meant we were just more careful. Where malloc is called, there had to be a free somewhere else in the program, and such checking was rigorous because in the case of ...


22

Because in order to free memory as soon as the reference counter hits zero, you have to keep a reference counter. And that doesn't come for free. Typically, it limits your throughput. There are generally two major strategies for implementing garbage collectors: tracing collectors and reference counting collectors. (There are others, but those are the ones ...


21

To get tough environment reliability specifically in C, here are some really concrete things that I've seen done. MISRA-C : The Automotive C subset. A bit like Ravenscar ADA/Java. watchdogs : ensure the program doesn't lock up ecc memory (sometimes) checksums: looking for flipping bits. I've seen all three of these in one system: 1) checksum the ...


21

Where are primitive fields stored? Primitive fields are stored as part of the object that is instantiated somewhere. The easiest way to think of where this is - is the heap. However, this is not always the case. As described in Java theory and practice: Urban performance legends, revisited: JVMs can use a technique called escape analysis, by which ...


21

for short running programs memory leaks are not as important; the OS will reclaim everything on termination, but they may cause other resources to not be released however short running is relative, a leak can spiral out of control in a few hours or stack up for weeks unnoticed my advice is to file a bug in the tracker with a proposed fix, if the lead cares ...


20

No, I don't think there is a specific name for a 3-byte word. Note that those 24 bits usually represent a RGB value, or a X, Y, depth coordinate, so usually those values are referred to with names specific to the API at hand.


20

CPU (its memory controller specifically) can take advantage of the fact that the memory is not mutated Advantage is, this fact saves compiler from using membar instructions when data is accessed. A memory barrier, also known as a membar, memory fence or fence instruction, is a type of barrier instruction which causes a central processing unit (CPU) ...


19

It's a challenging problem but I suspect there are a lot more clues to be found in the crashes you've already seen. Are you keeping careful records of crashes, to look for patterns? Are the few places really similar? In what way? What does the corrupt data look like? Zeros? Ascii? Patterns? Is there any multi-threading involved? Could it be a race ...


17

For most users the primary function of a smart phone is as a phone, followed by receiving text messages, and receiving e-mails. The designers of a smart phone OS must ensure that no application can interfere with these primary functions. The other constraint of mobile is battery life, any app which "spins" in the background it will consume current and ...


17

No, because a good kernel wipes the contents of memory before it is issued to a process to protect against exactly the kind of attack you propose. On Unixy systems, memory is allocated to processes by extending what's called the program break, which is the limit of virtually-addressable space a process can use. A process tells the kernel it wants to extend ...


17

You can certainly do that, but it may not save you as much complexity as you think. One of the main benefits of virtual memory is that it keeps different processes from needing to know which parts of memory other processes are using. On a system with virtual memory, one of the main jobs of the MMU is to give each process the illusion that the whole ...


17

One thing that should be mentioned explicitly is the impact of the speed of light. In this video Grace Hopper shows a piece of wire about a foot long, which is how far an electrical signal can travel in one nanosecond*. If a CPU is operating at 3GHz, then that implies a distance of 4" per clock cycle. This is a hard physical limit on memory access speeds. ...


16

Allocating a variable on the stack and deallocating it is a simple addition and subtraction of the stack pointer. Given that it happens anyway when entering a function means that local variables are so cheap that trying to optimize them to anything else will generally incur more cost. Putting it in the data segment will incur a cache cost, the stack will ...


15

It depends on the platform and implementation. C++ guarantees that the size of char is exactly one byte and at least 8 bits wide. Then, size of a short int is at least 16 bits and not smaller than char. Size of an int is at least as big as size of short int. Size of long int is at least 32 bits and not smaller than int. sizeof(char) == 1; sizeof(long int) ...


14

Each Java object has a header that contains information important for the JVM. The most important is a reference to the object's class (one machine word), and there are some flags used by the garbage collector and to manage synchronization (since every object can be synchronized on) which takes up another machine word (using partial words would be bad for ...


14

Yes, it's theoretically possible to read another process' released memory. It was the source of a number of privilege escalation attacks back in the day. Because of that, operating systems nowadays effectively zero out memory if it was previously allocated by another process. The reason you don't always see zeroed out memory is because it is more ...



Only top voted, non community-wiki answers of a minimum length are eligible