Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
StackBuffer.h File Reference
#include "Stroika/Foundation/StroikaPreComp.h"
#include "Stroika/Foundation/Memory/InlineBuffer.h"

Go to the source code of this file.

Namespaces

namespace  Stroika::Foundation
 

Typedefs

template<typename T = byte, size_t BUF_SIZE = StackBuffer_DefaultInlineSize<T> ()>
using Stroika::Foundation::Memory::StackBuffer = InlineBuffer< T, BUF_SIZE >
 Store variable sized (BUF_SIZE elements) array on the stack (.
 

Variables

constexpr size_t Stroika::Foundation::Memory::kStackBuffer_SizeIfLargerStackGuardCalled
 
constexpr size_t Stroika::Foundation::Memory::kStackBuffer_TargetInlineByteBufferSize = qStroika_Foundation_Common_Platform_Windows ? 2 * 1024 : 4 * 1024
 

Detailed Description

Note
Code-Status: Beta

Definition in file StackBuffer.h.

Typedef Documentation

◆ StackBuffer

template<typename T = byte, size_t BUF_SIZE = StackBuffer_DefaultInlineSize<T> ()>
using Stroika::Foundation::Memory::StackBuffer = typedef InlineBuffer<T, BUF_SIZE>

Store variable sized (BUF_SIZE elements) array on the stack (.

See also
also InlineBuffer<T,BUF_SIZE>), and on heap if it grows if needed

Typically, StackBuffer<> combines the performance of using a stack buffer (inline array on stack) to store arrays with the safety and flexability of using the free store (malloc).

Note
we used to have separate InlineBuffer and StackBuffer, but they did exactly the same thing. The only difference was the IDEA that StackBuffer might someday be re-implemented using alloca. I dont think thats plausible any longer, but something akin to it might be possible, so maintain the API difference for now.

Definition at line 59 of file StackBuffer.h.

Variable Documentation

◆ kStackBuffer_SizeIfLargerStackGuardCalled

constexpr size_t Stroika::Foundation::Memory::kStackBuffer_SizeIfLargerStackGuardCalled
constexpr
Initial value:
=
qStroika_Foundation_Common_Platform_Windows ? (sizeof (int) == 4 ? 4 : 8) * 1024 : 16 * 1024

On Windows, there is _chkstk which shows up in alot of profiles. Perhaps something similar for UNIX? Or just kernel does this automatically? Anyhow - target number we try - for performance reasons - to avoid more than this much in a stack frame.

https://www.codeguru.com/visual-studio/adventures-with-_chkstk/

Definition at line 25 of file StackBuffer.h.

◆ kStackBuffer_TargetInlineByteBufferSize

constexpr size_t Stroika::Foundation::Memory::kStackBuffer_TargetInlineByteBufferSize = qStroika_Foundation_Common_Platform_Windows ? 2 * 1024 : 4 * 1024
constexpr
Note
good to keep this small (around 2k) for Windows, cuz else _chkstack calls end up litering profiles in alot of functions even if along paths not actually used. COULD optimize those paths with specific value in usages, but seems reasonable to keep to 2k for now –LGP 2023-09-12

Definition at line 33 of file StackBuffer.h.