Tag Info

Hot answers tagged

86

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 ...


51

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 ...


45

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 ...


37

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. ...


36

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 ...


27

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 ...


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 ...


26

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 ...


23

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 ...


23

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 ...


22

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 ...


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

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

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 ...


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. ...


14

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

Small, fixed-size buffers might be used for any of the following reasons: constraints: either limited memory, or cache performance, or some other speed requirement that absolutely prohibits dynamic (re)allocation laziness: IMO this is mostly a hang-over from C, which didn't have a rich library container library correctness: if you're matching some external ...


14

Because it would be too expensive to do it continuously. "Mark and sweep" garbage collectors periodically sweep the memory space for objects that have been dereferenced. Generational garbage collectors sweep those objects first that are most likely to have been disposed of recently (which turns out statistically to be the objects most recently created). ...


13

.net utilizes a managed heap that exists in conjugation with the os memory functions built into windows. While the initial start up cost of the runtime can make the system look very memory intensive for large scale programs I have found it to not be that significant. You need to remember that the managed memory access is tested by thousands of developers ...


13

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 ...


13

The decimal point is not explicitly stored anywhere; that's a display issue. The following explanation is a simplification; I'm leaving out a lot of important details and my examples aren't meant to represent any real-world platform. It should give you a flavor of how floating-point values are represented in memory and the issues associated with them, ...


12

If the thread is actually running then the current instruction , and, any variables the thread is using must be in physical memory. Most (in fact nearly all) programs reside in virtual memory, and, most programs use virtual memory for storage of variables. Virtual addresses organized into chunks called pages (these are usually 4096 or 8192 byte blocks). ...


12

It's fairly common for embedded kernels not to use virtual memory, because protecting processes' memory spaces from each other isn't as important, and you generally have a relatively small amount of memory. In that case, the MMU is primarily used for protecting appropriate parts of the address space as read only, so you get segfaults when you want them. ...


11

Pretty much none. Even old technologies like COM, you can write custom deleters for the Standard pointers that will convert them in a very short time. For example, std::unique_ptr can be converted to uniquely hold a COM reference with five lines of a custom deleter. Even if you have to manually write your own resource handler, the prevalence of knowledge ...


11

There are two different memory limits. The virtual memory limit and the physical memory limit. Virtual Memory The virtual memory is limited by size and layout of address space available. Usually at the very beginning is the executable code and static data and past that grows the heap, while at the end is area reserved by kernel, before it the shared ...


11

Contrary to what anyone would say, knowing how memory works is important to know for any language, regardless of whether or not a specific language requires you to know it. For low level languages like C, memory addresses are very important to know because dedicating space to arrays or complex data structures requires a physical act of asking the operating ...



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