Questions tagged [realloc]

C library function for reallocating a dynamically allocated memory region.

man page

Wikipedia

References

Related Tags

1717 questions
6
votes
1 answer

segfault during write to the realloc'd area

I have a very frustrating problem. My application runs on a few machines flawlessly for a month. However, there is one machine on which my application crashes nearly every day because of segfault. It always crashes at the same instruction…
user2626585
6
votes
2 answers

Memory is not reallocating

I'm in the middle of a project and I'm trying to use malloc() and realloc(). I know when I malloc, it works, but when I use realloc, it doesn't change the amount of alloced memory at all. I've always though that realloc will re-allocate your…
Rob Avery IV
  • 3,562
  • 10
  • 48
  • 72
5
votes
2 answers

ARC & Malloc: EXEC_BAD_ACCESS

I have been working on a project for some time now, and I decided to make the jump to ARC. I came across some code that was bombing out every time, and I would like to know why. I have managed to simplify it down to this snippet: typedef __strong id…
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
5
votes
3 answers

Using realloc to expand buffer while reading from file crashes

I am writing some code that needs to read fasta files, so part of my code (included below) is a fasta parser. As a single sequence can span multiple lines in the fasta format, I need to concatenate multiple successive lines read from the file into a…
sirlark
  • 2,187
  • 2
  • 18
  • 28
5
votes
2 answers

Is there a linux equivalent of _aligned_realloc

Is there a linux equivalent of _aligned_realloc? I want to use realloc so I don't have to memcpy the data every time I resize it. Am I stuck with mmap? I only used mmap once is there a recommended way of implementing memory that will be resized a…
Eric Stotch
  • 141
  • 4
  • 19
5
votes
4 answers

Why use std::vector instead of realloc?

Here, in this question, it's stated that there is no realloc-like operator or function in c++. If you wish to resize an array, just just std::vector instead. I've even seen Stroustrup saying the same thing here. I believe it's not hard to implement…
StackExchange123
  • 1,871
  • 9
  • 24
5
votes
3 answers

How do you use realloc when you have a pointer to a pointer of a struct?

I have this array of structs and this function takes a pointer to the pointer of the array. The original size is 2, so whenever it reaches the size, I need to realloc and double the size. When this code runs, I get an invalid old size error from…
chuck
  • 53
  • 4
5
votes
6 answers

what will realloc do to the old pointer

I have a question about the realloc function. Will the content of old pointer be changed after apply realloc function? The code is main () { int *a, *b, i; a = calloc(5, sizeof(int)); for (i = 0; i < 5; i++) a[i] = 1; …
Shuai Xu
  • 89
  • 1
  • 5
5
votes
1 answer

c - realloc() on tokenized array: signal SIGABRT error

On line 56, I'm trying to resize an array: tokenArray = (char**) realloc(tokenArray, tokSize * (sizeof(char))); I get an error: (11972,0x7fff7ca4f300) malloc: * error for object 0x100105598: incorrect checksum for freed object - object was…
Kevin Welch
  • 1,488
  • 1
  • 9
  • 18
5
votes
1 answer

How do you use malloc to allocate memory for a structure?

The goal of my program is to read a file, and output the word with the max appearances, as well as the number of appearances. But I'm having issues with malloc and the syntax of it. This is the structure which malloc refers to: struct Word_setup { …
5
votes
3 answers

How does realloc() work?

Assuming that I have allocated memory using malloc(), if I do in my code: char *newline = realloc ( oldline , newsize ); // Assuming oldline is the pointer to which the starting address // of the memory which malloc() has returned, is assigned…
OldSchool
  • 2,123
  • 4
  • 23
  • 45
5
votes
1 answer

realloc: invalid next size, detected by glibc

My code: int args_size = 5; char** args; args = (char**) malloc(sizeof(char*) * args_size); // ... args = (char**) realloc(args, sizeof(char*) * (args_size += 5)); I want to increase the size by 5. But I get this error: *** glibc detected ***…
Sam
  • 1,842
  • 3
  • 19
  • 33
5
votes
5 answers

realloc not changíng size of array

Possible Duplicate: Realloc is not resizing array of pointers Can anyone tell me where my mistake is? this function should make an array of the characters supplied from stdin. I read some related questions but it was too complicated for me to…
Lukasik
  • 273
  • 1
  • 5
  • 10
5
votes
2 answers

realloc invalid old size

Disclaimer: This is homework. I am attempting it and do not expect or want anyone to do it for me. Just a few pointers (hehe) where I'm going wrong would be appreciated. The homework requires me to create an int* array that holds 10 elements, and…
Ayush
  • 41,754
  • 51
  • 164
  • 239
4
votes
3 answers

resizing buffer using realloc

If the area pointed to was moved, a free(ptr) is done. Can you please explain the above line about realloc()? This line is from a man page for calloc, malloc, realloc and free.
mawia
  • 9,169
  • 14
  • 48
  • 57