Shared members static or dynamic memory allocation C++
By : Cody Masten
Date : March 29 2020, 07:55 AM
This might help you The difference lies between whether you want to share the (member) object between all or some instances of your class. Static members are shared between all instances, i.e. they are not coupled to instances at all. They exist once and only once (even if there is no instance at all).
|
dynamic memory allocation,pointer members and destructors
By : ritika
Date : March 29 2020, 07:55 AM
To fix this issue Each time you call new, you have to delete it (except are shared pointers). So you have to delete the string in the destructor.
|
Dynamic Allocation for Class members in C++
By : beepee14
Date : March 29 2020, 07:55 AM
it helps some times I am trying to learn POO in C++. I have a problem regarding memory allocation in clases. I want to create a Stack Class. I have this code written in C++ : , You don't find the size of your stack like this: code :
int n_maxim = sizeof(stackArray) / sizeof(int);
class Stack {
private:
int *stackArray;
int topLevel;
int n_maxim;
public:
// Constructor without par
Stack() {
stackArray = new int[NMAX];
topLevel = -1; // stiva este NULL la inceput
n_maxim = NMAX;
}
Stack(int array_size) {
stackArray = new int[array_size];
topLevel = - 1;
n_maxim = array_size;
}
...
|
Dynamic allocation of objects with aligned members - possible solutions?
By : Juanjo Aguilella Mar
Date : March 29 2020, 07:55 AM
should help you out On Windows, malloc is 16-byte aligned ( msdn). If your platform malloc has lower alignment requirements, you need to use aligned versions of malloc for objects used by SSE. EDIT: If you have a specific class of objects that need SSE support you can redefine new/delete for that class only.
|
Dynamic memory allocation for structure, but what about its int or double members
By : zerdus
Date : March 29 2020, 07:55 AM
should help you out I cannot see any severe errors in your code though reasoning about it would be easier for me if you had written it in English. As you do malloc(sizeof(rekord)) you allocate memory to hold all members of a rekord. That is three char * pointers, an int and a double. You can write to those members immediately, no further allocation is needed. Of course, writing to a char * member is not really useful unless you are assigning it a pointer to some char buffer which you'd in turn obtain via malloc. For the int and double this is neither needed nor possible. So your code is correct here.
|