Questions tagged [static-allocation]

38 questions
0
votes
2 answers

Replace dynamic allocation with a static one

I have a project and I have to define an array of arrays of different dimensions (like a triangle) because I am not allowed to use std::vector or other container class. For this, I am using an array of pointers. Normally, I would do this: int*…
Stefan Octavian
  • 593
  • 6
  • 17
0
votes
2 answers

Understanding basic dynamic allocation example

I have a very basic doute concerning dynamic allocation. Studying the tree following possible syntaxes I have been said that they all are dynamic allocations. First: int* px(nullptr); px = new int; *px =20; Then a more concise one: int*…
0
votes
3 answers

Pointer to array Maintain counter of elements

I have an interface which multiple classes inheritance. class someInterface { virtual void someMethod() = 0; } class A : public someInterface { public: void someMethod() { …
Peter
  • 799
  • 4
  • 8
  • 23
0
votes
1 answer

c 2d array static initialization with preserved size

similar to 1D array declaration : char arr[]={[0 ... RESERVED_CHARS-1]=' ',[RESERVED_CHARS]='\0'}; please advice how / if possible to declare such 2D array ? #define SAY_MAX_MSG_LEN 6 #define REP_MAX_MSG_LEN 8 char *var_msg_out[][3]={\ {" Say…
Vlad
  • 63
  • 1
  • 5
0
votes
2 answers

Segmentation fault on function call with two dimensional array

I have the following code: #define MAXSAMPLES 1024 typedef int sample_t; typedef sample_t sub_band_t[MAXSAMPLES][MAXSAMPLES]; void blah(sample_t a[][MAXSAMPLES], int u0, int v0, int u1, int v1) { . . . . } int main(int argc, char *argv[]) { …
Dronacharya
  • 471
  • 1
  • 4
  • 15
-1
votes
2 answers

difference between dynamic allocation static allocation

MY question is In any programming language is dynamic memory allocation faster than static memory allocation? int main(int, char**) { int *pa = new int; // faster than int a; // ? return 0; }
karan
  • 398
  • 4
  • 5
-2
votes
1 answer

Reinitialize dynamically allocated memory

I am dynamically allocating memory at the beginning of a for using: Candset_t* emptycandset(void) { Candset_t* cset; cset = (Candset_t*)malloc(sizeof(Candset_t)); cset->size = 0; cset->maxsize = MAXSIZE; cset->dptr =…
1 2
3