realloc Questions
3
Solved
Is the behavior implementation defined? If NULL and size == 0 are passed to realloc():
int main(void)
{
int *ptr = NULL;
ptr = realloc(ptr, 0);
if(ptr == NULL)
{
printf("realloc fails.\n");...
Tritheism asked 17/2, 2017 at 16:22
4
If realloc fails and returns NULL is the former buffer free'd or it is kept intact? I didn't found that particular piece of information in the man page and I'm quite unsure what to do. If memory is...
Perhaps asked 22/10, 2009 at 12:56
6
Solved
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));
fo...
8
Solved
Question says it all but here is an example:
typedef struct mutable_t{
int count, max;
void **data;
} mutable_t;
void pushMutable(mutable_t *m, void *object)
{
if(m->count == m->max){
...
9
Solved
From what is written here, new allocates in free store while malloc uses heap and the two terms often mean the same thing.
From what is written here, realloc may move the memory block to a new loc...
Coley asked 14/11, 2015 at 8:25
7
Solved
2
Everyone knows that:
realloc resizes an existing block of memory or copies it to a larger block.
calloc ensures the memory is zeroed out and guards against arithmetic overflows and is generally g...
Lynda asked 12/2, 2015 at 20:49
2
Solved
I use realloc to resize the memory allocated:
char **get_channel_name(void)
{
char **result;
int n;
result = (char **) 0;
for (elem = snd_mixer_first_elem(handle), n = 0; elem; elem = snd_mi...
6
Solved
Can realloc fail in this case?
int *a = NULL;
a = calloc(100, sizeof(*a));
printf("1.ptr: %d\n", a);
a = realloc(a, 50 * sizeof(*a));
printf("2.ptr: %d\n", a);
if(a == NULL){
printf("Is it pos...
6
I am wondering whether the C or C++ standard guarantees that a pointer is not changed when realloc is called with a smaller (nonzero) size:
size_t n=1000;
T*ptr=(T*)malloc(n*sizeof(T));
//<--do...
5
Solved
I am doing an exercise for fun from KandR C programming book. The program is for finding the longest line from a set of lines entered by the user and then prints it.
Here is what I have written (p...
Crape asked 4/7, 2014 at 19:1
1
Solved
I have a memory interface that separates out acquiring address space from attaching backing store. (Under Linux the pool of address space managed by the interface is mmap'ed MAP_ANONYMOUS and MAP_N...
4
Solved
From Bjarne Stroustrup's FAQ:
If you feel the need for realloc() - and many do - then consider using
a standard library vector.
I'll preface my question by agreeing that std::vector is better...
3
Solved
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 ...
7
Solved
so I have a piece of memory allocated with malloc() and changed later with realloc().
At some point in my code I want to empty it, by this I mean essentially give it memory of 0. Something which w...
3
Solved
If there is not enough memory available at the original location:
Does it allocate multiple memory blocks and return a pointer pointing to one of those, with all blocks being internally linked wit...
Tennilletennis asked 29/1, 2014 at 16:54
3
Solved
I need to implement a simple dynamic array of pointers to a typedef'ed pointer.
Using realloc each time it's requested by the user, the array size will grow by sizeof(pointer).
So what I have is th...
Tube asked 11/1, 2014 at 20:2
6
Solved
From man realloc:The realloc() function returns a pointer to the newly allocated memory, which is suitably aligned for any kind of variable and may be different from ptr, or NULL if the request fai...
Michale asked 8/1, 2014 at 21:16
1
Solved
Consider the following (C11) code:
void *ptr = aligned_alloc(4096, 4096);
... // do something with 'ptr'
ptr = realloc(ptr, 6000);
Since the memory that ptr points to has a 4096-byte alignment f...
Tetrahedral asked 1/12, 2013 at 16:47
2
Solved
I am trying to realloc an array of structs when it runs out of space as I'm putting elements into it but I keep receiving a realloc stderr. The array of struct will eventually have 235,000 elements...
Renner asked 6/10, 2013 at 6:17
1
Solved
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.
...
3
Solved
I'm trying to make a code more efficient. I have something like this:
typedef struct{
...
}MAP;
MAP* pPtr=NULL;
MAP* pTemp=NULL;
int iCount=0;
while (!boolean){
pTemp=(MAP*)realloc(pPtr...
2
Solved
I was reading Richard Reese's new (May 2013) O'Reilly book "Understanding and Using C Pointers", and I have a question about some code therein, on page 87.
if (++length > maximumLength) {
cha...
2
Solved
While reading the https://mcmap.net/q/76169/-is-it-better-to-allocate-memory-in-the-power-of-two I have a question. What the Qt authors says in the Inside the Qt 4 Containers:
... QVector uses r...
Innovate asked 27/5, 2013 at 1:46
2
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 alwa...
© 2022 - 2024 — McMap. All rights reserved.