realloc Questions

1

I would like to build a dynamic malloced array of pthread_mutex that will grow over time (adding more mutexes). My question is whether they will still work if the array gets moved with realloc(). M...
Sirreverence asked 30/1, 2013 at 21:52

2

Solved

Just to situate the context: it's about a string pool, meaning a hash table with string keys (actually special strings that know their length, but I guess this detail is irrelevant here). The point...
Bes asked 12/12, 2012 at 17:11

3

Solved

Assume I have used ptr = malloc(old_size); to allocate a memory block with old_size bytes. Only the first header_size bytes is meaningful. I'm going to increase the size to new_size. new_size is g...
Fever asked 6/11, 2012 at 8:56

5

Solved

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 ...
Cloudland asked 10/10, 2012 at 18:31

3

Solved

I am learning how to create dynamic 1D arrays in C. The code below tries to do the following: Using malloc, create a dynamic array of length 10, that holds values of type double. Set each entry o...
Elman asked 1/10, 2012 at 15:6

3

How to read unlimited characters into a char* variable without specifying the size? For example, say I want to read the address of an employee that may also take multiple lines.
Eades asked 24/3, 2010 at 5:3

3

Solved

I was reading about realloc and got confused about a point mentioned there. Consider the code below: #include <stdio.h> #include <stdlib.h> int main () { int* ptr = NULL; ptr = rea...
Solarism asked 26/8, 2012 at 22:12

2

Solved

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 t...
Sinh asked 10/7, 2012 at 3:45

3

Solved

Sorry if this has been asked before, I haven't been able to find just what I am looking for. I am reading fields from a list and writing them to a block of memory. I could Walk the whole list, f...
Fleshpots asked 24/10, 2010 at 12:7

5

Solved

Let’s consider this very short snippet of code: #include <stdlib.h> int main() { char* a = malloc(20000); char* b = realloc(a, 5); free(b); return 0; } After reading the man pa...
Diamagnet asked 5/3, 2012 at 22:36

8

Solved

I have two questions. Do realloc() and memcpy() copy the entries in an array to another in a way faster than just iterating on each element O(N) ? If the answer is yes then what do you think is i...
Gonna asked 12/12, 2008 at 13:43

2

I am attempting to use realloc() in a Windows application. I am allocating a large block of memory, then using realloc() to shrink it down later once I know the correct size. I am finding that alt...
Extrabold asked 6/2, 2012 at 18:0

2

Solved

I'm having troubles understanding how realloc works. If I malloc'ed a buffer and copied data to that buffer, let's say "AB": +------------+ | A | B | \0 | +------------+ then I realloc'ed the...
Dorwin asked 4/2, 2012 at 17:23

2

Solved

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 s...
Mckenney asked 2/2, 2012 at 20:32

4

Solved

Some time ago a friend of mine told me not to use realloc because it's unsafe, but he couldn't tell me why, so I made some research on the subject and the nearest references to my doubt were: Firs...
Hall asked 30/1, 2012 at 22:11

3

Solved

I am getting invalid memory error on following code: printf(" %s\n","FINE 5"); printf("%s LENGTH IS: %d\n","FINE 6",strlen(": ")); buffer = (char *)realloc(buffer, strlen(buffer)* sizeof(cha...
Cassel asked 8/12, 2011 at 20:1

4

Solved

Its really a post for some advice in terms of the use of realloc, more specifically, if I could make use of it to simplify my existing code. Essentially, what the below does, it dynamically allocat...
Elanaeland asked 29/11, 2011 at 23:25

3

Solved

A different question inspired the following thought: Does std::vector<T> have to move all the elements when it increases its capacity? As far as I understand, the standard behaviour is for ...
Hexamerous asked 3/11, 2011 at 23:30

3

Solved

This is a homework assignment so I don't want to post any code, but I'm pretty stumped with the bug that I have. Currently I have a array that has been malloced and am copying the pointer t...
Bartels asked 23/10, 2011 at 22:38

6

Solved

While developing a piece of software for embedded system I used realloc() function many times. Now I've been said that I "should not use realloc() in embedded" without any explanation. Is realloc(...
Trainload asked 25/8, 2011 at 9:31

3

Solved

For example, I want such a function: char *dst = (char*)malloc(512); char *src = (char*)malloc(1024); ... dst = (char*)realloc(dst, 1024); memcpy(dst, src, 1024); As you see, I just want the fun...
Religieux asked 14/7, 2011 at 15:43

4

Solved

#inlcude <stdio.h> #inlcude <stdlib.h> #inlcude <string.h> int main() { char *buff = (char*)malloc(sizeof(char) * 5); char *str = "abcdefghijklmnopqrstuvwxyz"; memcpy (buff, ...
Ingrained asked 23/5, 2011 at 4:40

3

Solved

I have to read from a file an unknown number of rows and save them in to a structure (I would like to avoid a prepocessing to count the total number of elements). After the reading phase I have to ...
Manualmanubrium asked 11/5, 2011 at 14:24

5

Solved

How does one malloc a struct which is inside another struct? I would also like to malloc an array of items inside a struct and then realloc this array when needed, how is this done correctly? Cou...
Belt asked 28/3, 2011 at 22:24

1

Solved

I apologize for the lengthy code. I have a simple question, but I thought I include my code so it will be clear where I am coming from. I get a realloc corruption. I think the corruption is because...
Rodriguez asked 14/11, 2010 at 22:51

© 2022 - 2024 — McMap. All rights reserved.