realloc Questions
3
Solved
std::realloc is dangerous in c++ if the malloc'd memory contains non-pod types. It seems the only problem is that std::realloc wont call the type destructors if it cannot grow the memory in situ.
...
Maribeth asked 3/11, 2010 at 16:22
2
Solved
I'm trying to add 10 more elements to my struct that has been already malloc with a fixed sized of 20. This is the way I have my struct defined:
#include <stdio.h>
#include <stdlib.h>
...
8
Solved
In an earlier question, I asked about typecasting pointers, but was directed to the better solution of using the C++ allocation system instead of mallocs. (I am converting some C code to C++)
Howe...
Individual asked 6/10, 2010 at 2:52
5
Solved
The realloc reference says:
The function may move the memory block
to a new location, in which case the
new location is returned.
Does it mean that if I do this:
void foo() {
void* ptr = ...
4
Solved
When we reallocate memory via realloc(), are the previous contents over-written? I am trying to make a program which reallocates memory each time we enter the data into it.
Please tell me about m...
1
Solved
I encountered this small piece of code in this question, & wanted to know,
Can the realloc() function ever move a memory block to another location, when the memory space pointed to is shrinked...
Reborn asked 24/9, 2010 at 16:14
7
Solved
While there are lots of different sophisticated implementations of malloc / free for C/C++, I'm looking for a really simple and (especially) small one that works on a fixed-size buffer and supports...
5
Solved
realloc is used to reallocate the memory dynamically.
Suppose I have allocated 7 bytes using the malloc function and now I want to extend it to 30 bytes.
What will happen in the background if the...
Hoe asked 10/9, 2010 at 11:36
5
Solved
how does realloc know the size of original data?
void *realloc(void *ptr, size_t size);
So, if the implementation is like this:
temp = malloc(size);
memcpy(.. // How much to copy?
free(ptr)...
4
Solved
Can anyone summarize what is the correct usage of realloc()?
What do you do when realloc() fails?
From what I have seen so far, it seems that if realloc() fails, you have to free() old pointer. I...
11
Solved
I have a function which reallocs a pointer given as an argument to a new size. Now, the problem is that - according to the man page - realloc needs a pointer which has been returned by malloc or ca...
5
Solved
In C the standard memory handling functions are malloc(), realloc() and free(). However, C++ stdlib allocators only parallel two of them: there is no reallocation function. Of course, it would not ...
Quelpart asked 23/6, 2010 at 19:49
1
Solved
I'm having a problem with the realloc function. I'm using C only (so no vector) with LibCurl. The problem I'm having is that I'm getting the following error (realloc(): invalid next size) on ...
4
Solved
Given the following code:
int *a = NULL;
a = calloc(1, sizeof(*a));
printf("%d\n", a);
a = realloc(a, 0);
printf("%d\n", a);
return (0);
It returns:
4078904
0
Is this realloc equivalent to a...
2
Solved
I am porting a project to the iPhone and it uses realloc and memcpy which are not found. What is the header to include?
It's a project mixing Objective C and C++ and I am starting to be lost.
Tha...
Jiggle asked 17/2, 2010 at 19:21
9
Solved
5
Solved
In C++, I believe, a better way of dealing with reallocation is to use a STL vectors, as it guarantees the contiguous storage locations.
I have couple question to understand the difference:
Is the...
8
Solved
I'm trying to create a function which takes an array as an argument, adds values to it (increasing its size if necessary) and returns the count of items.
So far I have:
int main(int argc, char** a...
© 2022 - 2024 — McMap. All rights reserved.