Login Page - Create Account

Support Board


Date/Time: Tue, 17 Mar 2026 07:06:05 +0000



Post From: Adding support for persistent pointers to s_CustomChartBarInterface

[2026-01-25 18:31:40]
User719512 - Posts: 425
Until such time as s_CustomChartBarInterface supports GetPersistentPointer(), you can use GetPersistentInt64() as a workaround.
For full cleanup, use a persistent flag to detect study removal (not shown in proof of concept below).


You will want to TEST THOROUGHLY and don't just use the below blindly.
You will want to ensure you don't leak memory, clean up on study removal, etc.
Adding detailed logging with a "DEBUG" flag or #define will be valuable.


Windows uses a flat virtual address space with little-endian byte order on both x64 and ARM64, so the bit pattern of the pointer is preserved exactly during the cast and storage.
Pointers (void*) are 64-bit on both x64 and ARM64, matching the size of int64_t.


// Define a key for the persistent variable
const int POINTER_KEY = 100;

// Example struct or data to point to
struct MyCustomData {
int value;
};

// Your custom chart bar building function
SCSFExport CustomChartBarBuildingFunction(SCCustomChartBarInterfaceRef cbi) {
// Example: On first call or reload, allocate and store the pointer
// Or use a reload flag with another persistent int
if (cbi.IsFirstBarOfChart) {
MyCustomData* p_data = new MyCustomData(); // Dynamically allocate
p_data->value = 42; // Initialize

// Store pointer as int64_t
int64_t& stored_ptr = cbi.GetPersistentInt64(POINTER_KEY);
stored_ptr = reinterpret_cast<int64_t>(p_data);
}

// Retrieve and use the pointer in subsequent calls
int64_t& stored_ptr = cbi.GetPersistentInt64(POINTER_KEY);
MyCustomData* p_data = reinterpret_cast<MyCustomData*>(stored_ptr);