realloc Questions
0
According to the change log of C23, proposal n2464 was voted-in and implemented, making realloc(ptr, 0) explicitly undefined behavior, whereas it was supposedly implementation-defined in previous s...
Kaolinite asked 1/7 at 8:12
3
Solved
When I have a pointer which should repeatedly be used as argument to realloc and to save it's return value, I understand that realloc won't touch the old object if no allocation could take place, r...
1
Solved
I'm using a library that lets me override some of it's macros for how it allocates to the heap
#define STBI_MALLOC(sz) malloc(sz)
#define STBI_REALLOC(p,newsz) realloc(p,newsz)
#define STBI_FREE(p)...
Fertilize asked 23/4, 2021 at 7:2
2
Solved
Is there a linux equivalent of _aligned_realloc?
I want to use realloc so I don't have to memcpy the data every time I resize it. Am I stuck with mmap? I only used mmap once is there a recommended ...
Camp asked 17/11, 2020 at 23:12
5
Does it fail when it runs out of free memory similar to malloc or could there be other reasons?
Grussing asked 7/2, 2011 at 19:27
4
Here, in this question, it's stated that there is no realloc-like operator or function in c++. If you wish to resize an array, just just std::vector instead. I've even seen Stroustrup saying ...
Quicken asked 14/8, 2020 at 7:29
5
Solved
Simple question about the realloc function in C:
If I use realloc to shrink the memory block that a pointer is pointing to, does the "extra" memory get freed? Or does it need to be freed manually ...
Vitek asked 16/8, 2011 at 12:11
4
Solved
How can I realloc in C++? It seems to be missing from the language - there is new and delete but not resize!
I need it because as my program reads more data, I need to reallocate the buffer to hol...
Heaviness asked 14/8, 2010 at 10:39
4
Solved
If destination and source are the same, does memmove still "move" the data (or does it return directly)? What about realloc; what if the new size is the same as the old size?
1
Solved
How does realloc() reallocate the memory which was first allocated by malloc()?
I know that you need to use malloc() before you´re able to reallocate the memory, but I don´t understand how that r...
Necessitarianism asked 14/1, 2020 at 17:23
8
I am using realloc in every iteration of a for loop that iterates more that 10000 times.
Is this a good practice? Will realloc cause an error if it was called a lot of times?
Trinee asked 29/3, 2011 at 11:6
2
I can't find any source code for the realloc function and it seems to break the fundamental rule of C: it doesn't take the length of the memory to reallocate.
How is memory reallocated without kn...
2
Solved
Memory allocated by malloc can be reallocated with realloc. Is there a similar function for alloca? Reallocating stack memory could be useful when you don't want memory to be allocated on the heap,...
Cambria asked 31/5, 2019 at 10:5
3
Solved
Consider this simple program:
#include <string>
#include <sparsehash/dense_hash_map>
int main()
{
google::dense_hash_map<std::string, int> map;
map["foo"] = 0;
}
Compiling w...
Charlton asked 21/9, 2018 at 3:41
6
So I don't really know how to put the title this time. First of all I'd like to say that I've seen several comments on this page about warning if the question is related to "homework".
Mine is, but...
Harmonium asked 26/5, 2013 at 13:46
3
Solved
I'm trying to write a program which first dynamically initialises a queue array for 100 int elements. Whenever the queue is full and another element is supposed to be queued, the original array is ...
5
EDIT: I added two more benchmarks, to compare the use of realloc with the C array and of reserve() with the std::vector. From the last analysis it seems that realloc influences a lot, even if calle...
Olli asked 2/4, 2018 at 16:36
2
I have a question about dynamic memory allocation.
Context: I'm writing a program that reads a text file of words and counts the frequency with which each word occurs (one word per line).
This p...
Kaz asked 4/12, 2017 at 2:4
3
Solved
I am trying to load two double numbers from input into a two-dimensional array that is dynamically reallocated by each user input.
#include <stdio.h>
#include <stdlib.h>
int main(int ...
2
Solved
I know that trivially copyable objects can safely be copied my malloc into an appropriate storage location1 and that the destination object will have the same value as the source.
Is this also po...
Pacifically asked 19/10, 2017 at 20:53
7
Solved
If do the next:
int* array = malloc(10 * sizeof(int));
and them I use realloc:
array = realloc(array, 5 * sizeof(int));
On the second line (and only it), can it return NULL?
Okhotsk asked 25/8, 2012 at 20:14
1
Solved
There exist several aligned versions of the venerable malloc(), e.g.:
#include <stdlib.h>
int posix_memalign(void **memptr, size_t alignment, size_t size);
void *aligned_alloc(size_t alignme...
Undersigned asked 4/8, 2017 at 9:44
4
This is the way I've been taught to use realloc():
int *a = malloc(10);
a = realloc(a, 100); // Why do we do "a = .... ?"
if(a == NULL)
//Deal with problem.....
Isn't that redundant? Can't i ju...
7
Solved
I have a few related questions about managing aligned memory blocks. Cross-platform answers would be ideal. However, as I'm pretty sure a cross-platform solution does not exist, I'm mainly interest...
Tranship asked 21/2, 2011 at 1:12
4
I have cloned a large repo and got an error (after several attempts)
Clone succeeded, but checkout failed
When trying to fix this with
git checkout -f HEAD
an error comes back
Fatal: Ou...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.