Questions tagged [realloc]

C library function for reallocating a dynamically allocated memory region.

man page

Wikipedia

References

Related Tags

1717 questions
0
votes
1 answer

Resizing string arrays that may be too big

Some background: I'm writing a C function that reads text from a file into a dynamically reallocated array. I start off with BUF_SIZE character, read until I've hit the limit, then reallocate. When I'm finished, I append \0 at the end of the text…
Forest Katsch
  • 1,485
  • 2
  • 15
  • 26
0
votes
5 answers

Expand array of structs using realloc

I am passing a struct through a function like so... expandArrayofStructs(Container *container, int n) This container is one struct and inside of that struct is an array of another type of struct I'll call it inner. I would like to expand the size…
FunkyT
  • 51
  • 3
  • 8
0
votes
1 answer

Find growing realloc with valgrind

I have a program whose use of memory grows by 6Mb every minute. I've ran valgrind on it and cannot find any leaks. So I suspect that it's some kind of realloc inside the graphic libraries I use (and of which I do not have the source). It's a 32 bit…
dargaud
  • 2,431
  • 2
  • 26
  • 39
0
votes
2 answers

C realloc usage

I'm trying to dynamically increase memory of an int array, However I'm having issues getting it to work. It isn't expanding and adding more elements to the array, I'm not sure what I'm doing wrong. Please help! int* fibs = NULL; void genFibs(){ …
William McCarty
  • 769
  • 3
  • 12
  • 26
0
votes
2 answers

Realloc address causing an Abort (core dumped)

I attempted implementation of a new feature on working code. However, I know from commenting out that the following lines of code are causing my program to crash. tmp = (char*)realloc(list->array[list->size],…
ShowLove
  • 899
  • 1
  • 12
  • 21
0
votes
1 answer

C error: invalid operands of types 'int*' and 'unsigned int' to binary 'operator*'|

So, I get this error in C function. Variables: int* first_array = (int*) malloc(0); int first_array_length; int* second_array = (int*) malloc(0); int second_array_length; // Setting up first array set_up_array(first_array,…
0
votes
1 answer

Function with realloc crashes program after second run

it seems that after the second time in which the function realocVet runs, the error message "malloc: *** error for object 0x7f8bfac039b0: pointer being realloc'd was not allocated" appears. void realocVet (float *precoList, char *nomeList, short int…
user2344303
0
votes
3 answers

How to properly use free for specific struct type in C

I have looked through the other discussion and still cannot figure this out. I have a struct, typedef struct { char * word; int count; } wordType; In my code, I malloc each array[index].word and realloc the array of structs. How do I go about…
Busch
  • 857
  • 10
  • 29
0
votes
3 answers

Realloc using stdarg

I'm trying to concatenate strings using stdarg (library) header, but I'm doing something wrong. There is a easier way to concatenate strings using realloc? #include #include #include #include void…
0
votes
1 answer

Using realloc to shrink the string inside struct

I have a small question about using the realloc function. Assuming I have: typedef struct { char* location; int temp; int numberOfRec; }TEMP; Then I declare a pointer to this struct in the main and allocate the memory: int main() { TEMP*…
KurodaTsubasa
  • 25
  • 2
  • 5
0
votes
2 answers

realloc of array struct in other struct

My problem is in the line when I call realloc(), but works with the first "Elemento" #include #include using namespace std; typedef struct{ string palabra; string* significados; size_t tam; } Elemento; typedef struct{ …
0
votes
2 answers

Copying content of array to resized array in C++

I've searched through many topics here, but they didn't seem to answer me exactly. I'm trying to do some dynamic reallocation od arrays in C++. I can't use anything from STL libraries as I need to use this in homework where STL (vectors,...) is…
Saraph
  • 992
  • 1
  • 11
  • 25
0
votes
1 answer

strcpy corrupts char array (string value)

The function below tries to order strings on a linked list in ascending order. When it returns the new list, it becomes corrupted. void* order( void *ptr){ struct wordlist *head; head = (struct wordlist *) ptr; struct wordlist *first =…
gzg
  • 1,469
  • 6
  • 23
  • 39
0
votes
0 answers

Optimal Memory Utilization in realloc (splitting?)

I'm having difficulty with coding my realloc function. I have it working through standard memcpy procedure, but I can't get it optimized. I know there are two other cases I need to accommodate for: expanding the current block forward, and checking…
0
votes
2 answers

Reallocating memory correctly in c++

#include #include class circuitTypes{ protected: static int size; circuitTypes **Matrix; int input1,input2; int output1, output2; public: circuitTypes() {}; static int getSize() { return size; }; …
iiirxs
  • 4,493
  • 2
  • 20
  • 35