Questions tagged [dynamic-allocation]

Use for questions related to *dynamic allocation of memory*, such as `malloc()` in C, `new` in C++, etc. . Please notice that the tag is not language specific.

From Wikipedia: "C dynamic memory allocation refers to performing manual memory management for dynamic memory allocation in the C programming language via a group of functions in the C standard library, namely malloc, realloc, calloc and free."

Please notice that the tag is not language specific.

506 questions
0
votes
1 answer

Delete QMap value as a pointer

I have a QMap with key QString and with the value myClass. I've looked through the Qt documentation and decided to define value as pointer to myClass object. But, I'm puzzled with issue of how to remove both key and (pointer object allocated by new…
elgolondrino
  • 665
  • 9
  • 33
0
votes
1 answer

C. Dynamic Array of Struct

I'd like create dynamic array of struct player. I know size of struct, so i wouldn't like allocate memory for each struct. So i define struct player { uint32_t efficiency ; uint32_t number; } ; struct array { size_t size; struct…
PlushEngineCell
  • 775
  • 1
  • 7
  • 14
0
votes
1 answer

Dynamically allocating array of structs

I have a struct named clients, and i created this array of structs. typedef struct auxiliarRegistre{ char name[50]; char CPF[20]; char addr[100]; }clients; clients PrimaryClients[100]; I'm calling a function to insert the data into this arrays,…
PlayMa256
  • 6,603
  • 2
  • 34
  • 54
0
votes
0 answers

Memset an address into four bytes of allocated memory

EDIT: Thanks to Ipmcc, he has given me a solution in the comments. I would like to use memset to allocate a four-byte address into the first four bytes of memory that I have dynamically allocated. An example with comments of what I'd like to do is…
Tundra Fizz
  • 473
  • 3
  • 10
  • 25
0
votes
2 answers

Seg fault dynamically allocated 2d array

I have a homework assignment where I have to dynamically allocate a 2d array and i am getting seg faults when my arrays are long and skinny, such as 2x8, and the problem only occurs when certain values are in the array. here is my code for making…
0
votes
2 answers

2D dynamic allocation in C error when incrementing the pointer

I wanted to allocate a string array dynamically , the program is supposed to ask the user for characters and collect them in the first string in the array till letter 'q' is entered then the program starts adding the characters to the second line…
0
votes
1 answer

How to remove an element from a dynamically allocated array of objects with operator -= without using std::vectors?

Overloading the operator -=: RentACar& operator-=(const Automobile& av) In RentACar i have a dynamically allocated array of Automobile *a So lets say that if any a has the same a.brand with av.brand then that a should be removed and the allocated…
Stefan Stojkovski
  • 479
  • 2
  • 8
  • 17
0
votes
0 answers

Releasing the memory allocated for Window(s), Object(s), List(s)

To make a general idea: I am trying to develop an application which, in the state I've brought it to, uses a dozen of globally declared List(s) and List(s)>, where the "T"'s are generally Textboxes, and a Class. The Lists and Lists(of)Lists are used…
0
votes
2 answers

Passing one dimension of a 2D dynamic array to a function

I have a 2D array that I'm dynamically allocating at runtime, like so accData = calloc(nbox, sizeof(double *)); for(bb = 0; bb < nbox; bb++) accData[bb] = calloc(usedTime * usedChan, sizeof(double *)); and I want to only pass the second…
Kitchi
  • 1,874
  • 4
  • 28
  • 46
0
votes
2 answers

Dynamic array of IplImage - no match for ‘operator=’ error

I'm using dynamic array of IplImage type for storing some images (I would like to do the same thing with cvHistogram but get the same error) from which I need to extract histogram data. Unfortunately I'm getting the error and have no knowledge how…
Moirae
  • 139
  • 3
  • 14
0
votes
7 answers

Understanding delete operator in C++

Consider below code: #include #include using namespace std; class A{ public: int x; public: A(){x=0;} void fun1(){ cout << "fun1 is called \n"; cout << "Address of this is " << this…
Gaurav K
  • 2,864
  • 9
  • 39
  • 68
0
votes
2 answers

glibc detected realloc(): invalid next size: 0x

This code implement an extensible queue using realloc(), this is only a part of the original code. When I run this get an error: typedef uint32_t u32; typedef uint64_t u64; typedef struct _queue_t *queue_t; struct _queue_t { u32 *array; …
pabloapast
  • 75
  • 8
0
votes
3 answers

Segmentation fault (core dumped) on Ubuntu with matrix functions on C++

I'm trying to build a program in C++ that works a lot with matrices and functions of matrices. My code compiles normally, but when I try to execute it I get the message: Segmentation fault (core dumped) My code has a lot of function that look like…
0
votes
1 answer

c++ dynamic allocation with opencv exception

i have the following code. i used it after applying connected components code i have the wanted results from connected components but i'm trying using the following code to remove the very small or very high labels based on a threshold.but every…
Nermeeno Alami
  • 69
  • 1
  • 4
  • 9