.
Serenity
Okay, thanks a lot ! it really helped me.
TalkSick
Anonymous
Anyone from US, UK and EU(especially Netherlands)
Anonymous
How to edit a printed text?
Anonymous
you can use \b backspace
Serenity
If I dynamically allocate a struct and some particular fields in it , and I want to free it at the end, Is it sufficient to free the struct pointer or do I have to free each specific allocation I've executed before for each struct field ?
Asdew
You need to free everything you have allocated yourself.
Serenity
Okay but what is the logic behind that ?
frakw
Will this code cause memory leak?
class A
{
char *someHeapMemory;
public:
A() : someHeapMemory(new char[1000]) {}
~A() { delete[] someHeapMemory; }
};
class B
{
A* APtr;
public:
B() : APtr(new A[10]) {}
~B() { delete[] APtr; }
};
int main()
{
B* BPtr = new B[5];
delete[] BPtr;
return 0;
}
Anonymous
If that particular fields are allocated dynamically, you should free those field
Anonymous
Anonymous
A a;
A aa(a);
Calls delete twice on the same chunk of memory when a is destroyed
Anonymous
It will call a destructor to destruct Aptr in Bptr element
Anonymous
So that fine, but be cautious when use exception.
Marián
one thing that twists my mind a bit
Marián
Marián
in what scope is the EventHandler initialized and when is it popped from stack?
Marián
Marián
is the EventHandler object created on that += level scope?
eg on same level as evt1 is this in this scenario
frakw
I saw this problem on stackoverflow
https://stackoverflow.com/questions/677653/does-delete-on-a-pointer-to-a-subclass-call-the-base-class-destructor
but i don't know what if i change
B() : APtr(new A()) {} ~B() { delete APtr; }
To
B() : APtr(new A[10]) {} ~B() { delete[] APtr; }
Anonymous
Yes, you can add something verbose to A destructor for verification btw
frakw
MrILL
—
Dima
lol
Asdew
Malloc stores some data, such as the size, but malloc does not know anything about the actual data.
Asdew
If I understand you correctly, I think that's what I tried to say.
Asdew
Yes, free just doesn't know what the data you allocated has.
Marián
yeah but it certainly has longer lifetime
Marián
i mean this->hook appends it on vector on class-level scope
Marián
and it's being called and invoked from totally different scope
Marián
from scope that is on evt1 level
Marián
and it still lives, so i guess that operator overloading doesn't act like a normal function?
Marián
oh wait, it does copy
Marián
okay, this is embarassing, let's pretend we didn't see it
Anonymous
What type of projects are making passive incomes?
,_
It approves useful content sharing not a spam
Dima
Pavel
Anonymous
/get cppbook
Anonymous
/get cbook
Anonymous
/get cppbookguide
Anonymous
.
Artöm
Artöm
klimi
Ajay
struct COMPA{
bool operator()(pair<long,pair<long,long>> &a, pair<long,pair<long,long>> &b){
if(a.first!=b.first){
return a.first<b.first;
}
return a.second.first > b.second.first;
}
};
priority_queue<pair<long, pair<long, long>>, COMPA> q;
Ajay
Why does the above thing give compilation error? Why do I need to do it like
priority_queue<pair<long, pair<long, long>>, vector<pair<long, pair<long, long>>> , COMPA> q;?
Nikk
/notes
Artöm
Because comparator is the third template argument
Nikk
/noendl
Anonymous
/notes
Nikk
#noendl
Artöm
Yes
Ajay
so this is always in case of priority_queues?
Artöm
Anonymous
Ajay
Yes. But often T provides operator<
I hope T provides a operator< is alternative of providing a custom comparator as I did above, not making the comparator inside the class/structure of T for T.
Ajay
https://pastebin.com/pn35WKZ0
I don't understand why the vector and priority_queue in the above case produce different outputs, I mean how does the comparator function work in each of these cases?
Mar!o
What's the difference between vbroadcastsd and vbroadcastsdymm1 (AVX)
Artöm
int* is not char*
Artöm
fgets reads a string, not an int array
Artöm
Yes
Daniel
😹😹
Daniel
Yep
Serenity
If I advance a pointer, and I want to go back to the first value it has referred to , how can I do that ?
Serenity
It's a struct pointer
Marián
but nvm
Artöm
Harleen
Serenity
How to advance a pointer to pointer ?
Serenity
If I have int **x
Serenity
How do I increase the last pointer ?
Artöm
Which is the last?