Jul.11.2018 -- CAlive to introduce safe and managed pointers

11 views
Skip to first unread message

Rick C. Hodgin

unread,
Jul 11, 2018, 10:10:31 AM7/11/18
to CAlive Programming Language
CAlive will introduce the safe and managed keywords for use with pointers.  These will alter the way standard memory accesses are made.

With safe, it will check each access to see if it's in the valid range, and if not it will call the ptr_unsafe() function, which is either defined explicitly, or automatically injected by the compiler to trap to the debugger and/or cause an inquiry.  This ability is explicitly added to try and track down bugs in applications where something is being corrupted.  By defining everything as safe, every pointer allocation will contain additional information in a struct like this:

    struct SSafePointer
    {
        any*    p;         // Actual pointer
        u32/64  base;      // The base address this pointer is valid for
        u32/64  limit;     // The limit of valid data from that base
    };

Using this model, each pointer assignment copies meta data and enforces the range.  Each pointer increment or decrement is allowed, but the actual range is then tested against the base+limit range.

         s8* p1;   // A standard pointer to point to any s8 or string, can be invalid
    safe s8* p2;   // A safe pointer to point to any s8 or string, but one which contains
                   // meta information about its valid range, and tests are performed to
                   // make sure the data is in range before use.

With managed, pointers are created which point to pointers, so the underlying memory address can be moved without affecting the actual pointer value itself.  This allows memory to be swapped out to disk, or any other thing, through this additional level of indirection, but in this case the compiler automatically handles it for you.

-- 
Rick C. Hodgin

Reply all
Reply to author
Forward
0 new messages