I am using a dynamic array to represent a min-heap. There is a loop that removes minimum, and add random elements to the min-heap until some condition occur. Although I don't know how the length of the heap will change during run-time (there is a…
Is there such a thing? I mean some function that would reallocate memory without moving it if possible or do nothing if not possible. In Visual C there is _expand which does what I want. Does anybody know about equivalents for other platforms,…
I'm experimenting with malloc & realloc and came up with some code for the following problem:
I want to create a string of unknown size, without setting any limit. I could ask
the user for a nr of chars, but I rather resize the str as the user
…
Note: when I say "static string" here I mean memory that can not be handled by realloc.
Hi, I have written a procedure that takes a char * argument and I would like to create a duplicate IF the memory is not relocatable/resizable via realloc. As is,…
Possible Duplicate:
How do you realloc in C++?
I know that C++ arrays can be reallocated (expanded) using realloc() if memory has been allocated via malloc() or calloc(). My question is, how can I expand an array in C++ whose memory has been…
I have a function
void *srealloc(void * ptr , int size){
void *tmp = realloc(ptr , size);
if(tmp == NULL){
fprintf(stderr,"realloc of %u bytes failed", size);
exit(1);
}
return tmp;
}
My code that calls this runs…
I'm fairly new to C++ and new to pointers as well. I'm currently working on a stack and was trying to reallocate the memory for the stack as the size of the stack reaches the top however, I'm running into issues. I've already done a lot of research…
Relatively new C programmer here. I am reviewing the following code for a tutorial for a side project I am working on to practice C. The point of the abuf struct is to create a string that can be appended to. Here is the code:
#include…
I'm trying to use realloc() every loop, so I only use necessary memory for my int array in C, but the output values are changed. Nevertheless, when using Valgrind on my code, I have the right values.
I'm doing the first day of Advent of Code…
So I know that realloc() can follow 2 ways. The first way is allocating memory in a new address and freeing old memory. Second way is allocating memory in the same address so that you will only need to free that address. So in both ways, you only…
I have the next struct
struct Board
{
int width;
int height;
char **board;
}
And I would like to expand the **board, meaning I need more memory and thus the call to
realloc(). So my question is how do I do that - should I call realloc()…
I am trying to solve the following exercise in C:
"Consider a function dobuleArray() that takes in input an array and a
pointer to its size and gives as output the array doubled. Create an
array of size 1 to 4 as initial size. Then, start filling…
I want to concatenate in a string multiple sentences. At the moment my buffer is with fixed size 100, but I do not know the total count of the sentences to concatenate and this size can be not enough in the future. How can I define a string without…