Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>malloc</strong> allocates the amount of memory you ask in heap and then return a pointer to void (void *) that can be cast to whatever you want. </p> <p>It is <strong>responsibility of the programmer</strong> to use only the memory that has been allocate. Writing (and even reading in protected environment) where you are not supposed can cause all sort of random problems at <em>execution time</em>. If you are <em>lucky</em> your program crash immediately with an exception and you can quite easily find the bug and fix it. If you aren't lucky it will crash randomly or produce unexpected behaviors. </p> <p>For the <strong>Murphy's Law</strong>, <em>"Anything that can go wrong, will go wrong"</em> and as a corollary of that, <em>"It will go wrong at the right time, producing the most large amount of damage"</em>. It is sadly true. The only way to prevent that, is to avoid that in the language that you can actually do something like that.</p> <p>Modern languages do <strong>not</strong> allow the programmer to do write in memory where he/she is not supposed (at least doing standard programming). That is how Java got a lot of its traction. I prefer <strong>C++</strong> to C. You can still make damages using pointers but it is less likely. That is the reason why <em>Smart Pointers</em> are so popular.</p> <p>In order to fix these kind of problems, a <em>debug version</em> of the malloc library can be handy. You need to call a check function periodically to sense if the memory was corrupted. When I used to work intensively on C/C++ at work, we used <strong>Rational Purify</strong> that in practice replace the standard malloc (new in C++) and free (delete in C++) and it is able to return quite accurate report on where the program did something it was not supposed. However you will never be sure 100% that you do not have any error in your code. If you have a condition that happen extremely rarely, when you execute the program you may not incur in that condition. It will eventually happen in production on the most busy day on the most sensitive data (according to Murphy's Law ;-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload