Let's say I'm writing a custom vector using the std::allocator to wrap new and delete.
When the number of elements exceed the vector's capacity, I would like to reallocate the buffer to something larger. I can achieve this easily by calling…
I want to move a large chunk of data i've got in my memory. Unfortunately this data is saved as an array, and i cannot change that. I can't use circular arrays, because the same memory is also used by a couple of fortran methods i do not want to…
I have a c++ program running on a Windows 7 machine with 12GB memory.
The compiler and linker is Visual Studio 2013 Express.
the program uses a library OGDF.
I compiled the library source codes into a static library with Release X64 configuration…
I have a function to read a file using the read() system call and return a char pointer with the data read from the file. The function reallocates space if necessary. After a specific point the read fails with the error "Bad Address". The minimum…
Yeah, it's a homework question, so givemetehkodezplsthx! :)
Anyway, here's what I need to do:
I need to have a class which will have among its attributes array of objects of another class. The proper way to do this in my opinion would be to use…
typedef struct {
int count;
int *items;
}set;
set* set_alloc(set *src, int num);
int set_insert(set *s, int num);
int main() {
set *A = NULL;
A = set_alloc(A, 0);
A = set_alloc(A, 1); //this and line below is part of inserting…
When you call realloc() you should check whether the function failed before assigning the returned pointer to the pointer passed as a parameter to the function...
I've always followed this rule.
Now is it necessary to follow this rule when you…
My question is about realloc.
The following code works correctly (with no warning):
#include
#include
int main ()
{
int num=10;
int *vet;
int i;
for (i=0; i
Currently I have set up an array to hold 50 packets created by the program. However I would like to change this array to use malloc instead along with the use of storing a maximum of 50 pieces of information just as the current array does.
Here's…
I've got a doubt about using std::vector.
If I got a structure with a std::vector object with nondefined space in the memory, if it need to be reallocate (the std::vector), is the structure also reallocated? or only the std::vector?
For…
I have written following code to get clear with malloc and realloc.
I have initialized pointer using malloc and then using realloc, i am increasing the size of the array.
But i get following error when i run the…
I am trying to use realloc function as making the array bigger as the user entered names. It gives me an error when I add 5. element, the error like :
* glibc detected ./a.out: realloc(): invalid next size: 0x00000000017d2010 **
And the code…