tviejo / 42Cursus-Webserv

0 stars 1 forks source link

Smart pointer classes + custom Array classes. #1

Closed Haliris closed 2 weeks ago

Haliris commented 2 weeks ago

WIP.

Implements two custom Smart Pointer classes. Smart Pointers handle the memory they point to themselves, reducing overhead in the codebase and hopefully preventing memory errors.

UniquePtr that take ownership of the memory they point to, useful for objects that would have a long lifetime and from which we would want to take references or short lived raw pointers from to conduct checks and such. Naturally, UniquePtrs cannot be copied whatsoever.

SharedPtr do not take single ownership of the memory they point to and can be copied. Needed if we have to share ownership of an object accross multiples instances. Hopefully this should not happen too often as they have performance implications to their instanciation and are more error prone.

In short, we should use these whenever we want to write new ..., in any other cases, a raw pointer or a reference would be fine. I did not bother implementing weak_pointer because I do not think we will need it.

I will implement the Array class later and mark this as ready for review when I am done.

I also did not implement make_unique and make_shared, because we do not have auto in C++98, making those two utility functions rather pointless as we would need to explicitly specify the type of the pointer regardless, so might as well use the constructors directly.

Haliris commented 2 weeks ago

Ready

Haliris commented 2 weeks ago

change include to includes please

Done