olli
Exceptions do not leak if you use RAII
Exceptions can lead to leakage
Dima
using exceptions in cxx is like rip
BinaryByter
Ludovic 'Archivist'
Ludovic 'Archivist'
Exceptions can lead to leakage
Explain me how you can leak memory due to exceptions if you properly do RAII
olli
Explain me how you can leak memory due to exceptions if you properly do RAII
that was one reason why std::make_unique has been added to C++14
olli
what does make_unique do?
creates a unique pointer without leaking memory
Ludovic 'Archivist'
what does make_unique do?
Construct a unique_ptr whose memory is allocated from a std::allocator directly
Ludovic 'Archivist'
BTW, memory leaks are the least dangerous ones
Ludovic 'Archivist'
C can literally leak anything
BinaryByter
creates a unique pointer without leaking memory
where is the difference between unique_ptr and shared_ptr?
BinaryByter
both just wrap c-style pointers
Ludovic 'Archivist'
You want to leak something tragic? File descriptors
olli
where is the difference between unique_ptr and shared_ptr?
you cannot copy a unique_ptr, it uses no reference counting. Once a unique_ptr goes out of scope it ideallocates the memory. a shared_ptr uses ref counting and the last one will release the memory
Ludovic 'Archivist'
both just wrap c-style pointers
The behavior is different
Ибраги́м
what does make_unique do?
Use Google u piece of shit. [That's how nice it sounds] unique_ptr<maxi> MX = std::make_unique<maxi>(args_go_here);
Dima
rip
Ludovic 'Archivist'
Ludovic 'Archivist'
Also, leaks of memory space
Or leaks of threads or process ids
Ludovic 'Archivist'
Leaks of file locks
Ludovic 'Archivist'
Leaks of memory locks
Ludovic 'Archivist'
C can very easily leak any of that
Ибраги́м
Use Google u piece of shit. sorry
NP. Just telling that sometimes u might wanna overlook some people and don't trash them yet
Ибраги́м
Ludovic 'Archivist'
Ибраги́м
sorryhhhhhh ;_;
Your butt pls . Spanking spree
BinaryByter
It is in the name
yea but how does he count the references?
olli
how does ref counting work?
on each copy you increase the count by one. In the destructor you decrease it. Once you reach zero references you know the object is no longer being reachable and you can delete it
BinaryByter
Your butt pls . Spanking spree
please don't. i'd like to use it to sit
Ludovic 'Archivist'
yea but how does he count the references?
You count things with a counter
Ludovic 'Archivist'
In general, a pointer to a std::atomic_int
BinaryByter
oh ok
olli
oh that makes sense. but the counter is a global variable?
there is a global state that each shared_ptr has a pointer to. But not totally global
Ludovic 'Archivist'
In general, a pointer to a std::atomic_int
A shared_ptr contain a pointer to one as well as the target pointer, copying the shared_ptr increases the counter, destruction decreases the counter
olli
Construct a unique_ptr whose memory is allocated from a std::allocator directly
are you sure about the std::allocator part? http://eel.is/c++draft/unique.ptr.create#2 "Unlike std::make_shared (which has std::allocate_shared), std::make_unique does not have an allocator-aware counterpart"
olli
New uses the standard allocator
https://en.cppreference.com/w/cpp/memory/allocator/allocate allocator uses new
olli
so no
olli
A = B implies B = A
that's no equality
Ludovic 'Archivist'
that's no equality
If you prefer wording A if and only if B implies B if and only if A
olli
New uses the standard allocator
but this is not right, since :: operator new is called by allocate ant not the other way around
olli
doesn't matter in the end though :)
Ludovic 'Archivist'
Ludovic 'Archivist'
Apart if your system have far and short pointers
Onur
Its the link in my message above
olli
Its the link in my message above
no :( unfortunately you need to explicitly use the "share" button
Onur
https://onlinegdb.com/ryxxhKNbYX oh lol my bad
olli
https://onlinegdb.com/ryxxhKNbYX oh lol my bad
Interessting... thanks for sharing Clang and ICC report it being ill-formed GCC and MSVC compile it just fine...
Onur
I assume this is a bug right?
olli
I assume this is a bug right?
yes, I think it is a bug in GCC and MSVC. I think the code should not compile
olli
not using an auto paramter won't compile anywhere https://godbolt.org/z/OxBD3x
Onur
hmm
Onur
is there a resource that specify how type deduction should work?
olli
is there a resource that specify how type deduction should work?
yes the standard does (http://eel.is/c++draft/dcl.spec.auto) this might cover it http://eel.is/c++draft/dcl.spec.auto#9
Onur
Thanks
~danishsem
Hello..what does this group function ??
Dima
lol
~danishsem
Okok....i just knew about it
~danishsem
Sorry everyone
Alignant
So, guys. I have a question
Alignant
Is it possible to do something like this
Alignant
Using boost
Alignant
So it works on windows too
Alignant
In short: I want a so-library to return its path and address. In runtime