mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
samples: add Hello/Demo samples for most BRUTAL packages (#19)
Add samples/, a collection of single-file .NET 10 apps run with `dotnet run <file>.cs`. Hello/ has one minimal sample per package that has a public API, many of them headless; Demo/ has fuller programs that combine packages into a more interesting application. samples/README.md indexes every sample and covers the layout, error handling and per-OS requirements.
This commit is contained in:
parent
4ac91e105e
commit
7a3b72d843
1 changed files with 4599 additions and 1 deletions
35
samples/Hello/HelloCollections.cs
Normal file
35
samples/Hello/HelloCollections.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* HelloCollections
|
||||
*
|
||||
* Uses NativeList<T>, a growable list backed by unmanaged memory: add, insert,
|
||||
* remove, iterate and edit it as a span.
|
||||
*/
|
||||
|
||||
#:package Ahwoo.Brutal.Collections@2026.10.1
|
||||
#:package Ahwoo.Brutal.Core@2026.10.1
|
||||
|
||||
// RIAN: This package will be greatly improved in an upcoming release of custom allocators, and collections that use them.
|
||||
|
||||
using Brutal.Collections;
|
||||
|
||||
Run();
|
||||
|
||||
static void Run()
|
||||
{
|
||||
// A List<T>-like collection backed by unmanaged memory, freed when Run returns.
|
||||
using var list = new NativeList<int>();
|
||||
|
||||
list.Add(1);
|
||||
list.AddRange([2, 3, 4, 5]);
|
||||
list.Insert(0, 0);
|
||||
list.RemoveAt(3);
|
||||
|
||||
Console.WriteLine($"Count = {(int)list.Count}, Capacity = {(int)list.Capacity}");
|
||||
|
||||
foreach (var value in list)
|
||||
Console.WriteLine(value);
|
||||
|
||||
var span = list.AsSpan();
|
||||
span.Reverse();
|
||||
Console.WriteLine($"Reversed in place: {string.Join(", ", span.ToArray())}");
|
||||
}
|
||||
Loading…
Reference in a new issue