https://github.com/marcvincenti/smartpointer
Smart pointers prevent most situations of memory leaks by making the memory deallocation automatic.
https://github.com/marcvincenti/smartpointer
heap pointer smart-pointer stack
Last synced: 2 months ago
JSON representation
Smart pointers prevent most situations of memory leaks by making the memory deallocation automatic.
- Host: GitHub
- URL: https://github.com/marcvincenti/smartpointer
- Owner: marcvincenti
- License: mit
- Created: 2016-05-12T22:04:06.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-19T12:23:08.000Z (over 8 years ago)
- Last Synced: 2025-02-07T23:24:46.342Z (4 months ago)
- Topics: heap, pointer, smart-pointer, stack
- Language: C++
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SmartPointer
Smart Pointer implementation without any pool or any previous memory allocated.
## How it works ?
In this case, we choose to work with contexts. We actually have just one context struct (this is why it's not thread safe today).
```cpp
extern bool sp_contexte_new;
extern bool sp_contexte_array;
extern void* sp_contexte_addr;
extern std::size_t sp_contexte_size;
```+ The **new** indicate the object is in the heap (*i.e.* we called the instruction).
+ The **array** indicate if it's an array or not.
+ And **addr**, **size** are the address and size of the new object.Now, we now for each SmartPointer if the pointed object is in the stack or in the heap.
Each SmartPointer also contains the number of references from the stack **and** from the heap to the pointed object,
the address of the pointed object, if the SmartPointer itself is in an array and is in the heap (because of the contexts uses).```cpp
template
struct compteur
{
T * ptr;
int ref_cnt_tas;
int ref_cnt_pile;
bool heap = true; //l'objet pointé est-il dans le tas?
};
```And later in class SmartPointer :
```cpp
private://Attributs
bool is_array;//le smartPointeur contient-il un tableau ?
bool tas;//le smartPointeur est-il dans le tas ?
compteur * refer;//la structure reste à la fin de l'objet
```And finally, we have :
```cpp
typedef std::pair>> paireZone;
typedef std::map>> mapZone;
```Where **mapZone** is a map with the address of the pointed object as key and a pair of the size of the object
and a list of pointer which are pointing this object.