Questions tagged [realloc]

C library function for reallocating a dynamically allocated memory region.

man page

Wikipedia

References

Related Tags

1717 questions
0
votes
2 answers

Reallocing a char*

I am trying to do a function that will store in a char array some information to print on it: int offset = 0; size_t size = 1; char *data = NULL; data = malloc(sizeof(char)); void create(t_var *var){ size_t sizeLine =…
0
votes
1 answer

How to update and array of pointers to elements of an array after realloc moves the memory location of that array

I am a beginner and am having a really hard time with dynamic memory allocation. If anyone can help me with this problem, I would be really grateful. I allocate some memory using malloc to an array Node using: struct nodeT { int id; nodeT *parent,…
Wajahat
  • 453
  • 5
  • 8
0
votes
2 answers

Realloc Crashing on Passed Pointer

I can't seem to find a question that matches exactly what I'm doing, so here goes. Below is a cut down version of my C app down to where a problem lies. I know it's ugly code and missing a few error checks but it was just for me to figure out this…
Fmstrat
  • 1,492
  • 2
  • 17
  • 24
0
votes
4 answers

c, malloc and realloc an array of structs

Let's say I have a struct called Thing. If I want to have an array of "Thing", yet it doesn't have a fixed size (dynamic), how do I go about allocating space for it? Do I initially malloc space for the array itself, and then have to realloc space…
Andrew Backes
  • 1,884
  • 4
  • 21
  • 37
0
votes
3 answers

How to free pointers within a dynamic array when realloc fails?

Possible Duplicate: How to handle realloc when it fails due to memory? Let's say I have an array of pointers char **pointers_to_pChar = 0; pointers_to_pChar = (char **)malloc(sizeof(char *) * SIZE); for (i = 0; i < SIZE; ++i) { …
Hayri Uğur Koltuk
  • 2,970
  • 4
  • 31
  • 60
0
votes
2 answers

Dynamic Array of Structures

I have a few questions about a piece of code that I have found on web, which is located at http://www.c.happycodings.com/Data_Structures/code9.html. Why is strarray defined as **? Do we have to first malloc() the array, and then malloc() each…
groove
  • 273
  • 2
  • 7
  • 17
0
votes
3 answers

Malloc and Realloc relation, How does it handle when the required space is not available in memory

Possible Duplicate: realloc and malloc functions #include #include void main() { int *p; p = malloc(6); p = realloc(p, 10); if (p == NULL) { printf("error"); // when does p point to null consider i have enough…
john
  • 53
  • 1
  • 6
0
votes
3 answers

realloc fails (in C) for a pointer to an array

I'm trying to dynamically allocate memory for (what is essentially) a 2-dimensional array of chars - i.e - an array of strings. My code is as follows: typedef char LineType[MAX_CHARS+1]; LineType* lines; int c = 0; int N = 2; lines = (LineType *)…
Klayhamn
  • 25
  • 6
0
votes
2 answers

Failing to reallocate memory when in if statement

When trying to reallocate memory I crash when using this code: //value of i is currently 4096 while((c = recv(sock, htmlbff + q, MAXDATASIZE, 0)) > 0) { if((i - q) < MAXDATASIZE) { i *= 2; if(!(tmp = realloc(htmlbff,…
Keith Miller
  • 1,337
  • 1
  • 16
  • 32
0
votes
3 answers

delete partial memory of the pointer

Is there any way i can delete the partial memory of the pointer.? for example char *c = new char[1000]; sprintf(c,"this is it"); As it can be seen a lot of memory is getting wasted here. can I free the memory more than the required.?
user649558
  • 57
  • 5
0
votes
4 answers

libc detected *** ./textfileread.exe: realloc(): invalid next size: 0x08643008

I have declared double pointer in main and allocate memory like this char **group_name; group_name = realloc( NULL, 1); group_name[0] = realloc(NULL ,20); I have passed this array to a function, group_count(object, count, group_name); which uses…
Haris_tech
  • 83
  • 1
  • 2
  • 13
0
votes
1 answer

mex memory allocation mxRealloc

I have to read a matrix of double, handling its values and insert them in a new matrix, whose one of its dimension is unkwown at the beginning. In a static memory allocation, my code is: #include void mexFunction( int nlhs, mxArray *plhs[],…
no_name
  • 1,315
  • 2
  • 16
  • 20
0
votes
1 answer

C programming: How do I use realloc in this program?

I have to write a program that stores and prints out integers from memory. I have to use realloc. Basically, the program allocates size for 2 ints. When input is given 2 ints it should reallocate space for 1 more int and prints out double. Next,…
SharkTiles
  • 585
  • 3
  • 9
  • 22
0
votes
1 answer

Error In realloc or free in message queue example

Here i am getting some problems in realloc or free in message queue example. In below program i got error of double free or corruption at the time of last message received from the message queue. I send 10 messages in message queue and i received 10…
user1089679
  • 2,328
  • 8
  • 41
  • 51
0
votes
1 answer

realloc(): Invalid next size C dump

I'm having some serious trouble with this function: When the trace reaches the realloc, it blows up. I've checked similar questions on this subject but nothing came out. I hope you can help me. Do you see anything wrong? char **tokenizepath(char…
Vladimir
  • 393
  • 3
  • 16
1 2 3
99
100