About 2,940,000 results
Open links in new tab
  1. When and why to use malloc - Stack Overflow

    malloc allows you to allocate much larger memory spaces than the one allocated simply using student p; or int x[n];. The reason being malloc allocates the space on heap while the other allocates it on the stack. The C programming language manages memory …

  2. C Programming: malloc() inside another function - Stack Overflow

    I need help with malloc() inside another function.. I'm passing a pointer and size to the function from my main() and I would like to allocate memory for that pointer dynamically using malloc() from inside that called function, but what I see is that.... the memory, which is getting allocated, is for the pointer declared within my called function and not for the pointer which is inside the …

  3. alloc, malloc, and alloca — What's the difference?

    Sep 21, 2015 · The Microsoft Visual C++ runtime includes an Alloc() function which is somewhat similar to malloc(), but this is also not part of the C standard. malloc() allocates memory on the process heap. Memory allocated using malloc() will remain on the heap until it is freed using free(). alloca() allocates memory within the current function's stack frame.

  4. c - How malloc works? - Stack Overflow

    The call to malloc will either succeed in returning a logically contiguous block of memory from your program's HEAP memory space equal to the size requested or it will fail with a NULL pointer. "Logically contiguous" means that with a malloc of this type:

  5. malloc - Why, or when, do you need to dynamically allocate …

    It can hide the bug of a missing declaration (implicit declarations were permitted prior to C.99), and results in undefined behavior. Always prefer taking the result of malloc() without a cast. malloc() is declared to return void *, and in C, a conversion between void * and another pointer type is always permitted (modulo type qualifiers like ...

  6. How to correctly use malloc and free memory? - Stack Overflow

    Jul 4, 2014 · If these are true, don't use malloc/free, but just use local auto variables which are allocated from the stack instead of the heap. For example, this is simpler and easier to maintain { double myPtr[5]; ...

  7. When should I use malloc in C and when don't I?

    Malloc is therefore always useful when you deal with arbitrary sized data, like reading file contents or dealing with sockets and you're not aware of the length of the data to process. Of course, in a trivial example like the one you gave, malloc is not the magical "right tool for the right job", but for more complex cases ( creating an ...

  8. Is malloc () initializing allocated array to zero? - Stack Overflow

    Jul 26, 2017 · The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free(). Apart from calloc() you can use the memset() function to zero out a block of memory.

  9. c++ - Malloc and constructors - Stack Overflow

    Jun 8, 2010 · [malloc, calloc, and realloc] implicitly create objects ([intro.object]) in the returned region of storage and return a pointer to a suitable created object. In the case of calloc and realloc, the objects are created before the storage is zeroed or copied, respectively. - [c.malloc] §5. C++98 - C++17

  10. c - malloc implementation? - Stack Overflow

    Mar 24, 2011 · In malloc, if the list is not empty, you search for a block large enough to satisfy the request and return it. If the list is empty or if no such block can be found, you call sbrk to allocate some memory from the operating system. in free , you …

Refresh