Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions strong_ptr/0.2.0/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 658343661697615b65b17d651caa172a
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file not shown.
Binary file added strong_ptr/0.2.0/.doctrees/api/exceptions.doctree
Binary file not shown.
Binary file added strong_ptr/0.2.0/.doctrees/api/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added strong_ptr/0.2.0/.doctrees/environment.pickle
Binary file not shown.
Binary file added strong_ptr/0.2.0/.doctrees/index.doctree
Binary file not shown.
Binary file added strong_ptr/0.2.0/_images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions strong_ptr/0.2.0/_sources/api/enable_strong_from_this.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# enable_strong_from_this\<T\>

Defined in namespace `mem`

*import strong_ptr;*

```{doxygenclass} v1::enable_strong_from_this
```
18 changes: 18 additions & 0 deletions strong_ptr/0.2.0/_sources/api/exceptions.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Exceptions

Defined in namespace `mem`

*import strong_ptr;*

```{doxygenclass} v1::exception
```

## out_of_range

```{doxygenstruct} v1::out_of_range
```

## nullptr_access

```{doxygenstruct} v1::nullptr_access
```
17 changes: 17 additions & 0 deletions strong_ptr/0.2.0/_sources/api/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
API
====

Defined in namespace ``mem``

*import strong_ptr;*

.. toctree::
:caption: Types
:maxdepth: 2

strong_ptr
monotonic_allocator
exceptions
optional_ptr
enable_strong_from_this
weak_ptr
102 changes: 102 additions & 0 deletions strong_ptr/0.2.0/_sources/api/monotonic_allocator.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# monotonic_allocator\<MemorySize\>

Defined in namespace `mem`

*import strong_ptr;*

A stack-allocated monotonic memory arena for use with `std::pmr` allocators.
Allocations advance sequentially through a fixed-size buffer. If the allocator
is destroyed while allocations are still outstanding, `std::terminate` is
called.

Use `make_monotonic_allocator<N>()` to create instances.

## Usage Examples

### Basic allocation and deallocation

```cpp
import strong_ptr;

// Create a monotonic allocator with 32 bytes of storage
auto allocator = mem::make_monotonic_allocator<32>();

// Allocate memory using the -> operator
auto* raw = allocator->allocate(sizeof(int), alignof(int));
auto* value = static_cast<int*>(raw);
*value = 42;

// Must deallocate before the allocator is destroyed,
// otherwise std::terminate is called
allocator->deallocate(raw, sizeof(int));
```

### Using with strong_ptr

```cpp
import strong_ptr;

// Create an allocator with enough space for the object + control block
auto allocator = mem::make_monotonic_allocator<256>();

// Pass the allocator as the memory resource for strong_ptr
auto ptr = mem::make_strong_ptr<int>(allocator.resource(), 42);
// ptr is automatically deallocated when all references are released
```

### Overflow behavior

Allocating beyond the buffer size throws `std::bad_alloc`:

```cpp
import strong_ptr;

auto allocator = mem::make_monotonic_allocator<8>();

// Allocate 8 bytes (fills the buffer)
auto* p1 = allocator->allocate(sizeof(int), alignof(int));
auto* p2 = allocator->allocate(sizeof(int), alignof(int));

// This will throw std::bad_alloc — no space left
try {
auto* p3 = allocator->allocate(sizeof(int), alignof(int));
} catch (std::bad_alloc const&) {
// Handle out-of-memory
}

allocator->deallocate(p1, sizeof(int));
allocator->deallocate(p2, sizeof(int));
```

### Leak detection

If allocations are not fully deallocated before the allocator is destroyed,
`std::terminate` is called:

```cpp
import strong_ptr;

{
auto allocator = mem::make_monotonic_allocator<32>();
auto* raw = allocator->allocate(sizeof(int), alignof(int));
// Forgetting to deallocate here will call std::terminate
// when allocator goes out of scope!
}
```

## APIs

### Factory Function

```{doxygenfunction} v1::make_monotonic_allocator
```

### Memory Resource + Storage Hybrid Object

```{doxygenstruct} v1::monotonic_allocator
```

### Memory Resource Implementation

```{doxygenstruct} v1::monotonic_allocator_base
```
8 changes: 8 additions & 0 deletions strong_ptr/0.2.0/_sources/api/optional_ptr.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# optional_ptr\<T\>

Defined in namespace `mem`

*import strong_ptr;*

```{doxygenclass} v1::optional_ptr
```
58 changes: 58 additions & 0 deletions strong_ptr/0.2.0/_sources/api/strong_ptr.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# strong_ptr\<T\>

Defined in namespace `mem`

*import strong_ptr;*

## Usage Example

```C++
#include <cassert>
#include <memory_resource>

import strong_ptr;

struct sensor {
int id;
float calibration;
};

int main()
{
// Create an allocator (or use your own pmr memory resource)
auto allocator = mem::make_monotonic_allocator<4096>();

// Create a strong_ptr - always valid, never null
auto s = mem::make_strong_ptr<sensor>(allocator, 0x13, 3.14f);

assert(s->id == 0x13);
assert(s.use_count() == 1);

// Share ownership
auto s2 = s;
assert(s.use_count() == 2);

// Create a weak reference (does not extend lifetime)
mem::weak_ptr<sensor> weak = s;

// Lock the weak_ptr to get an optional_ptr
mem::optional_ptr<sensor> maybe = weak.lock();
if (maybe) {
assert(maybe->id == 0x13);
}

return 0;
}
```

## make_strong_ptr\<T\>

Factory function for creating a `strong_ptr`.

```{doxygenfunction} v1::make_strong_ptr
```

## Class API

```{doxygenclass} v1::strong_ptr
```
8 changes: 8 additions & 0 deletions strong_ptr/0.2.0/_sources/api/weak_ptr.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# weak_ptr\<T\>

Defined in namespace `mem`

*import strong_ptr;*

```{doxygenclass} v1::weak_ptr
```
18 changes: 18 additions & 0 deletions strong_ptr/0.2.0/_sources/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
strong_ptr API documentation
============================

.. image:: _static/logo.png
:width: 200
:align: center
:alt: libhal logo

**Welcome to strong_ptr API documentation**

A non-null shared pointer for memory-constrained systems. Provides reference
counted smart pointers with polymorphic allocator support.

.. toctree::
:caption: strong_ptr Docs
:maxdepth: 5

api/index
Loading