Hot answers tagged

12

The internet. When you have multiple computers networked together there is no such thing as "the word size". Every computer has its own idea how big it's bus is. But they all agree on bytes (even if they can't agree on byte order). So we keep making bytes addressable. It helps with compatibility issues. It's a carry over from the days of 8 bit computing ...


9

I was wondering what exactly memory cleaner software do? In the best case, they do absolutely nothing. If you're lucky. Sometimes, they will actually free up RAM by deleting caches or forcing processes out of RAM. The thing is: free RAM is actually bad. RAM is much faster than hard disk, and it is also much more expensive. So, you should be using as much ...


9

There is no such thing like a "heap variable". You have invented a new term, so expecting others to explain you the threading behaviour of this new thing does not make much sense to me. There is, of course, "heap memory", and malloc returns a block of such memory. The start the adress of that memory can be stored in a pointer variable, ...


8

The C Standard requires that the implementation must be able to read and write single bytes. If you have an array char a[100] and one thread increases a[0] by 1, while another thread increases a[1] by 1, it is required that the implementation doesn't introduce any race condition. This is the case even if your code runs on a server with two sockets (that is ...


7

Rosetta 2 employs Just-In-Time compilation with dynamic optimization, just like, for example, the Oracle HotSpot JVM (and most others as well, e.g. IBM J9 / Eclipse OpenJ9), the Microsoft .NET CLR, all mainstream ECMAScript implementations (GraalJS, V8, SpiderMonkey, JavaScriptCore), the PyPy, GraalPython, IronPython, and Jython Python implementations, the ...


7

Initially I cannot understand your question, because the phrase "heap variable" is not described with sufficient detail and clarity, such that its meaning is a bit ambiguous. Each call to malloc gets assigned a different address. That address assignment happens during the call to malloc, not before, not after. When a thread function is executed on ...


6

Computer memory does not care about types, but does care about word size. A word consists of multiple bytes. The CPU's instruction set has instructions for reading or writing (or atomically modifying) a word of memory, but not all addresses can be used for such instructions: the pointer used for such instructions must be suitably aligned. Which alignments ...


6

You do want to use pointers because you want to represent an object that can be present or absent, depending on the enclosing object's state. But dealing with raw pointers correctly is very tricky: Raw pointers are prone to bugs, segfaults, use-after-free vulnerabilities, memory leaks, and frequently break if exceptions are involved. The solution is to use ...


4

Note: This is not a full answer. This is intended to introduce a mental framework to help anyone parse the existing varied answers to this questions. (0.A) Before you start reading: Are you on an educational program, studying for a course, or preparing for an examination? If this is the case, the institution that is in charge of your study is also in charge ...


4

Logically you will update just the byte. Note that a byte is already a logical concept. On a hardware level there are no bytes. In a modern computer there will be a lot of electronics in between the registers of the CPU and the memory cells of the main working memory, the CPU (or should I say instructions) have no direct control over the memory anyway. There ...


4

The CPU (at least, my CPU) always reads or writes 64 bytes at a time. This is called a "cache line". If you give it an instruction to write one byte, it will read 64 bytes, update 1, and eventually, it will write 64 bytes. (If you keep updating the same 64 bytes, it won't need to keep reading and writing them over and over. Also, the CPU can store many ...


4

In most programming languages, an out-of-memory condition is reported by means of an exception that gets thrown. If this exception is not handled by the application, then the unhandled exception causes the application to crash. To avoid the crash, you need to catch the exception and handle it in a sensible way. What a sensible way is to handle out-of-memory ...


4

Frankly spoken, if you have trouble to fix bugs caused by faulty memory management for a single executable, splitting up the program into multiple executables won't change this - at least, not directly. Of course, what you may be able to achieve by a multi-exec is to prevent your program system to crash completely. You wrote you have a design in mind with ...


4

If the process asks for 100MB, there has to be a contiguous 100MB free in the address space of the process (virtual memory), but those addresses can be mapped to non-contiguous pages of physical memory. The allocated addresses might not even be backed by physical pages until they are written to – Linux happily overcommits memory. On 64 bit systems it's ...


3

You don't fix memory management issues by breaking your program up into multiple executables - you fix memory management issues by fixing your memory management code. I know that's not a satisfactory answer, but it is the answer. C is not an easy language to learn, and I do not recommend it as a first language for anyone. It's an important language, yes, ...


3

"Stack frame" is a concept, or a convention. It is created to help programmers create programs (whether from assembly language or from higher-level languages) that can work together correctly. One crucial requirement of getting pieces of code to work together is that the caller and the callee must agree on how data is passed via the stack and/or ...


3

The default stack mechanism in assembly language is limited to the pushing and poping of the return address when you call a subbroutine. By default, there is no additional things stored on the stack when you make a CALL At assembly level, the closest thing to a local variable is the CPU register. The problem with a CALL, is that the called subroutine ...


3

It is generally serialized because serialization is the lowest common denominator, thus it is the easiest thing to code to and verify. When this becomes a limitation, you can look at your specific problem and see if there is a better solution. For example, if the large data objects in Python are actually numpy arrays, numpy exposes its internals with a C ...


3

It's not so much the compiler that decides, but the software developers creating the compiler. And they decide that based on what makes sense for the processor, and what customers (developers who use the compiler) want. For example, if you write a C compiler for a 64 bit ARM processor, your types can reasonably be 8, 16, 32 or 64 bit based on the hardware. ...


3

Yes. Most languages do allow variable sharing been threads without serialisation. In some languages, you can even share variables between processes using shared memory. Yes, you're correct that synchronisation is a problem in all languages that supports it. The most common and most basic way to solve the synchronisation issue is using a simple lock, also ...


3

Anything that the CPU needs from the virtual address will be loaded into the RAM when needed. Data is not loaded/written into RAM when the CPU reads data at some address (there is actually usually a swapping mechanism and swap space that loads into physical memory when reading, but I assume this is not what you are looking for). A process can write data at ...


3

CPUs have instruction sets, add two numbers, jump forward 3 instructions, if this is true run the next instruction, if not skip and instruction etc https://en.wikipedia.org/wiki/Instruction_set_architecture The 1s and 0s are stored in the memory of the computer and grouped together and read as instructions or data, ie run instruction number 3 or data ie take ...


2

All modern microprocessors physically read and write to memory in units larger than one byte, but allow the content of individual bytes to be changed.


2

So I was musing how can I securely change the value so that it isn't available to poking? In JavaScript, you cannot. However, there is a need to delete sensitive data, so other languages have workarounds. For example, in Java 8 the Destroyable interface was added so that sensitive objects can be cleanly destroyed, but this requires implementation support. ...


2

How should I provide generic typing and allocation for a collection library ... ? Establish boundaries Without scope limits, this task will evolve into a re-creation of C++. Assuming that is not the goal, maintain design limitations. Divide and Conquer Set up the collection library to handle only void * objects and void * keying. There is so much design ...


2

What you describe in your question looks very similar to an emulator for a CPU. Even if you are not exactly writing that, you can use the information on CPU emulators as inspiration for solving problems you encounter. If you are actually writing an emulator, keep in mind that nearly all processors cheat in that they use some non-memory storage for ...


2

TL;DR #1 The game application code that you will be writing that which will be making use of a Stack Allocator is responsible for determining (1) when to read the marker, (2) which scope should the marker be associated with, and (3) when to use the marker to free the allocations. The second responsibility is essentially the scope lifetime analysis for your ...


2

Most running programs push and pop things on the stack during function invocation and return. Usually a high level language program will provide a user-defined main, which is called by some language or runtime startup code, which is the first code run in the program. We can write a C-style program in assembly language by providing a main function — this will ...


2

what are the exact steps that take place and how is memory allocated to the member functions and the attributes of the class and in what order? This is language (and in some cases, implementation) specific. In a fair number of languages (e.g. Python, JavaScript), the allocation of memory is not a concept which is exposed by the language so your question ...


2

Asking about RAM is wrong, what counts is address space. If your OS is using virtual memory (which is most likely the case), then the mapping of address space to RAM is arbitrary and can change at any time, so address space counts. The address space assigned to a process is (almost) free and can be huge; how much of it is used is what actually costs. So in ...


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