How do malloc() and free() work?

OK some answers about malloc were already posted. The more interesting part is how free works (and in this direction, malloc too can be understood better). In many malloc/free implementations, free does normally not return the memory to the operating system (or at least only in rare cases). The reason is that you will get gaps in … Read more

malloc for struct and pointer in C

No, you’re not allocating memory for y->x twice. Instead, you’re allocating memory for the structure (which includes a pointer) plus something for that pointer to point to. Think of it this way: So you actually need the two allocations (1 and 2) to store everything. Additionally, your type should be struct Vector *y since it’s a pointer, and you should never cast the return value … Read more

Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) standard C memory issue

Check the return value of strtok. In your code here strtok is returning a NULL pointer and according to documentation, A null pointer is returned if there are no tokens left to retrieve. which matches my original guess that because the address code is 0x0 there’s a NULL pointer deference somewhere. Obviously, the following call to atoi is expecting a non-NULL pointer … Read more

Deleting a dynamically allocated 2D array

In reality, an array of pointers pointed to by a pointer is still an array of integral data types or numbers to hold the memory addresses. You should use delete[] for both. Also, yes, a new[] implies a delete[]. When you create an array of arrays, you’re actually creating an array of numbers that happen to hold the memory address for another array … Read more

Oracle startup not possible – ORA-00845: MEMORY_TARGET not supported on this system – but memory size seems to be fine

You might be using Automatic Memory Management (AMM). AMM uses two initialization parameters: MEMORY_TARGET MEMORY_MAX_TARGET The shared memory file system should have enough space to accommodate the MEMORY_TARGET and MEMORY_MAX_TARGET values. To verify: In UNIX/Linux, you will have to set the shared memory file system accordingly. Verify: Set: For example,

Is there a way to delete created variables, functions, etc from the memory of the interpreter?

You can delete individual names with del: or you can remove them from the globals() object: This is just an example loop; it defensively only deletes names that do not start with an underscore, making a (not unreasoned) assumption that you only used names without an underscore at the start in your interpreter. You could use a hard-coded … Read more