Questions tagged [realloc]

C library function for reallocating a dynamically allocated memory region.

man page

Wikipedia

References

Related Tags

1717 questions
0
votes
3 answers

filling up memory using realloc

The question might seem little trivial,i'm trying to write a program in C,which just eats away memory as much as it could before OOM gets invoked and kills it.Although,i initially used malloc() with memset(),i decided to try realloc() this time.I'm…
hmmm
  • 93
  • 2
  • 9
0
votes
1 answer

Free() function in C does not produce any error on freeing realloced data, but does not free the actual content. What can be the reason?

So I faced with an issues when I allocate some space, then I reallocate this space inside the recursive function and then I try to free this space outside of recursive function. Free() does not proceed any error, but as debugging shows I still have…
YohanRoth
  • 3,153
  • 4
  • 31
  • 58
0
votes
0 answers

Losing values with iterative realloc in C

I am working in C with Netbeans8.0 I have to read files in an iterative approach to get list of words. That is, in single iteration a file is read into an array of strings and then merge this array into a single array. void merge_array(char** a,int*…
aswathi p
  • 13
  • 3
0
votes
1 answer

overload delete[] operator to allow shrinkable arrays of types with destructor

We're trying to overload the delete[] operator to achieve shrinkable oriented to objects arrays. It works fine with data types without specific destructor. When the data type has a specified destructor, the new[] operator needs extra bytes. Could…
ncomputers
  • 3,680
  • 1
  • 15
  • 16
0
votes
1 answer

Expand an array with realloc inside of a function - Pointers?

I'm sure that the answer to this is me not understanding Pointers and References properly! So at the start of my C file I define a struct for people: typedef struct { char id[4]; int age; char name[128]; } people; Then inside of main()…
Westyfield2
  • 83
  • 1
  • 1
  • 5
0
votes
1 answer

realloc in recursion in trees

I am trying to find the maximum sum leaf to root path in a Binary Tree as in below http://www.geeksforgeeks.org/find-the-maximum-sum-path-in-a-binary-tree/ 1) I am unable to find why the path doesn't get printed in the main() Is this because of…
sparco
  • 85
  • 1
  • 7
0
votes
1 answer

What does realloc do in this code snippet?

I was going through the relloc example in C here . I could not figure out exactly what realloc() was doing in this snippet, because even when I commented out the realloc statement the program ran just fine. I am attaching the Code here again so…
thebenman
  • 1,621
  • 14
  • 35
0
votes
3 answers

Variable Arguments in C creating error in Valgrind

I was trying to run a program which uses a function concat_str. It can take in multiple arguments as strings and the end of arguments is denoted by "quit". The code for my function is given below: char *concat_str(char *str1, ...) { va_list…
0aslam0
  • 1,797
  • 5
  • 25
  • 42
0
votes
4 answers

c++ realloc same pointer warranty

Using the std::realloc function: If the new size is smaller, does it always have warranty to keep the memory block on the same position and only make it smaller, or it can move sometimes the whole block? The reason to ask this, is that we'are…
ncomputers
  • 3,680
  • 1
  • 15
  • 16
0
votes
4 answers

C double freeing error

Some starters: creating a dynamic array of a data structure called fractions. Fractions has functions for setting, printing, intiting etc. I kept getting an error for double freeing or corruption, along with a lot of gibberish from the memory…
0
votes
1 answer

Why does realloc() and free() fail in my code?

I have some problem with realloc(): int main(int argc, char* argv[]) { int* amis; int saisie, cpt = 1; while(saisie != -1) { printf("Entrer les notes -1 pour quitter :"); scanf("%d", &saisie); if (cpt == 1) { …
Timo
  • 497
  • 10
  • 21
0
votes
1 answer

Reallocating 2d array - valgrind errors

I am getting a bus error in a huge application that I have when I try to reallocate a 2d int array. Trying to narrow down the problem, I generated a small code only with the reallocations. Question: Valgrind complains a bit without crashing. Are…
Rubem_blah
  • 73
  • 5
0
votes
3 answers

Can I use std::realloc to prevent redundant memory allocation?

I need to allocate space for a temporary array once per iteration. I try to use realloc each iteration to optimize memory using. Like that: int *a = (int*)std::alloc(2 * sizeof(int)); for(int i=0; i
user1312837
  • 1,268
  • 1
  • 11
  • 29
0
votes
1 answer

realloc string table in C crash on the 4th iteration

Although there were several answers here regarding this issue: I still couldn't fit them to the following code, as it segfault on the 4th iteration of processFile: #include #include #include #include…
0
votes
2 answers

Trying to take multiple string inputs

Practice.c #include #include #include #define ARR 32 int main(void){ int MEM=64; char arr[ARR],*p=(char *)calloc(MEM,(sizeof(char))),*q=NULL; int i=0,j=1; printf("\nEnter String : "); while(j){ …
phougatv
  • 881
  • 2
  • 12
  • 29