Skip to content

Commit

Permalink
Remove appvayor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
etcimon committed Dec 30, 2023
1 parent b08dcb4 commit ec95ff3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 191 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*.lib
*.pdb
*.a
*-unittest
*-unittest
*~
96 changes: 49 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[![Build Status](https://ci.appveyor.com/api/projects/status/github/etcimon/memutils?branch=master&svg=true)](https://ci.appveyor.com/project/etcimon/memutils)
[![CI](https://github.com/etcimon/memutils/actions/workflows/ci.yml/badge.svg)](https://github.com/etcimon/memutils/actions/workflows/ci.yml)

The `memutils` library provides a set of 4 enhanced allocators tweaked for better performance depending on the scope.
A new allocation syntax comes with many benefits, including the easy replacement of allocators.

- `AppMem` : The AppMem Allocator pipes through the original garbage collection, but is integrated to support the new syntax and recommends manual management. If the `DebugAllocator` is disabled, automatic garbage collection works through this allocator but it will *not* call any explicit destructors.
- `AppMem` : The AppMem Allocator pipes through the original garbage collection, but is integrated to support the new syntax and recommends manual management. If the `DebugAllocator` is disabled, automatic garbage collection works through this allocator but it will _not_ call any explicit destructors.
- `ThreadMem`: This allocator is fine tuned for thread-local heap allocations and doesn't slow down due to locks or additional pressure on the GC.
- `SecureMem`: When storing sensitive data such as private certificates, passwords or keys, the CryptoSafe allocator
enhances safety by zeroising the memory after being freed, and optionally it can use a memory pool (SecurePool)
that doesn't get dumped to disk on a crash or during OS sleep/hibernation.
enhances safety by zeroising the memory after being freed, and optionally it can use a memory pool (SecurePool)
that doesn't get dumped to disk on a crash or during OS sleep/hibernation.
- `alloc!T`: Overrides the GC using the [PoolStack](https://github.com/etcimon/memutils/blob/master/source/memutils/scoped.d#L121), or falls back on `new` if no pools are available.

The allocator-friendly containers are:

- `Vector`: An array.
- `Array`: A `RefCounted` vector (allows containers to share ownership).
- `HashMap`: A hash map.
Expand All @@ -20,32 +20,33 @@ The allocator-friendly containers are:
- `DictionaryList`: Similar to a MultiMap in C++, but implemented as a linear search array

The allocator-friendly lifetime management objects are:

- `RefCounted`: Similar to shared_ptr in C++, it's also compatible with interface casting.
- `Unique`: Similar to unique_ptr in C++, by default it will consider objects to have been created with `new`, but if a custom allocator is specified it will destroy an object pointer allocated from the same allocator with `.free`.
- `ScopedPool`: Adds a `Pool` to the `PoolStack` until the end of scope, allowing an override of GC allocations when calling `alloc` anywhere beyond its creation.

The `RefCounted` object makes use of a new `mixin template`, available to replace the `alias this m_obj;` idiom, it can be found in `memutils.helpers`. It enables the proxying of operators (including operator overloads) from the underlying object. Type inference will not work for callback delegates used in methods such as `opApply`, but essentially it allows the most similar experience to base interfaces.

The `RefCounted` object makes use of a new `mixin template`, available to replace the `alias this m_obj;` idiom, it can be found in `memutils.helpers`. It enables the proxying of operators (including operator overloads) from the underlying object. Type inference will not work for callback delegates used in methods such as `opApply`, but essentially it allows the most similar experience to base interfaces.

### Examples:

```D
struct MyString {
mixin Embed!m_obj; // This object impersonates a string!
string m_obj;
// Custom methods extend the features of the `string` base type!
void toInt() { }
}
void main() {
void main() {
string ms = MyString.init; // implicit casting also works
MyString ms2 = MyString("Hello");
// You can "dereference" the underlying object with `opStar()`
assert(is(typeof(*ms2) == string));
assert(is(typeof(*ms2) == string));
}
```
---------------

---

You can use `AppMem`, `ThreadMem`, `SecureMem` for array or object allocations!

Expand All @@ -58,7 +59,7 @@ You can use `AppMem`, `ThreadMem`, `SecureMem` for array or object allocations!
assert(ub.length == 150);
```

--------------
---

The `Vector` container, like every other container, takes ownership of the underlying data.

Expand All @@ -74,47 +75,48 @@ The `Vector` container, like every other container, takes ownership of the under
assert(gcVal == "Hello there");
writeln(val); // SEGMENTATION FAULT: The data was collected! (this is a good thing).
```
--------------

---

The Array type is a RefCounted!(Vector), it allows a hash map to take partial
ownership, because objects marked @disable this(this) are not compatible with the containers.

```D
{
HashMap!(string, Array!char) hmap;
hmap["hey"] = Array!(char)("Hello there!");
assert(hmap["hey"][] == "Hello there!");
}
```
```D
{
HashMap!(string, Array!char) hmap;
hmap["hey"] = Array!(char)("Hello there!");
assert(hmap["hey"][] == "Hello there!");
}
```

--------------
---

Using the GC (AppMem) for containers will still call `free()` by default, you must copy the data if you want it to escape the scope.
Using the GC (AppMem) for containers will still call `free()` by default, you must copy the data if you want it to escape the scope.

```D
string gcVal;
{
Vector!(char, AppMem) data;
data ~= "Hello there";
gcVal = data[].idup;
}
assert(gcVal == "Hello there");
```
```D
string gcVal;
{
Vector!(char, AppMem) data;
data ~= "Hello there";
gcVal = data[].idup;
}
assert(gcVal == "Hello there");
```

--------------
---

The `Unique` lifetime management object takes ownership of GC-allocated memory by default.
It will free the memory explicitely when it goes out of scope, and it works as an object member!
The `Unique` lifetime management object takes ownership of GC-allocated memory by default.
It will free the memory explicitely when it goes out of scope, and it works as an object member!

```D
class A {
int a;
}
A a = new A;
{ Unique!A = a; }
assert(a is null);
```
-------------

See source/tests.d for more examples.
```D
class A {
int a;
}
A a = new A;
{ Unique!A = a; }
assert(a is null);
```

---

See source/tests.d for more examples.
143 changes: 0 additions & 143 deletions appveyor.yml

This file was deleted.

Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo.webp
Binary file not shown.

0 comments on commit ec95ff3

Please sign in to comment.