Lions and Tigers and Pointers, oh my!

Pages: 12
What else have I forgotten?


its hard to say what you know, knew, and forgot.
But a few fun things..
negative indexing is often just not allowed in languages, and is generally frowned upon. But say you wanted to store a signed byte in a counting sort type structure (where array[value] tells you how many of that [value] you have). If you just take a 256 sized array and grab a pointer in the middle, you can then check [-120] from the pointer as a negative array index in the shifted array location.

private/locked/hidden member access/modification. If you can get the address of it, you can hand wave away any const or other preventions and directly access things. Its not generally useful, but if you get into a library (most common for me, hardware interfaces that refuse to expose things that the library knows but won't share) that is determined to keep you out, C and C++ raw pointers can get you (at risk, if the library changes the address can move) the value.

and a lot of it is obsolete. I used to do the copy elision that is now part of C++ using pointers... a function would modify a static variable with the latest result and a pointer to that would directly access it without copying (good for OOP where the copy costs something). Its really nice not having to do that sort of thing, and there are still many other use cases where a pointer to data avoids a copy of that data cleanly... an example is if you want to sort fat data just for a display of it sorted by whatever key, but you don't really want to rearrange its true storage, you can just sort a container of pointers to it which is faster if the objects are fat and disposable as nothing was really done.

Heh heh heh, I remember doing weird stuff poking around memory like that. Writing TSR keyboard drivers for DOS, and stuff to play with Mode X on the VGA card.

Forgetting stuff is sad.


I actually just came across an interesting article about old stuff like that:

    The Lost Art of Structure Packing by esr
    http://www.catb.org/esr/structure-packing/

(I was considering if I could get the compiler to preprocess me some information about whether the code was being optimized for size, lol.)
compiler to preprocess me some information about whether the code was being optimized for size

I've noticed the recent official VS 2022 release (17.10.3) now shows size and alignment info when pointer hovering over non-POD entities in one's code in the IDE. WinAPI data types and C++ classes and the like from what little I've seen.

I personally don't find the info all that useful, but then I'm just a self-taught programming hobbyist. I trust the VS compiler to optimize efficiently so I don't have to.

The article does make for interesting reading...
Alignment is (or at least was) relevant for vectorization. While compiler might be able to optimize many things today, some alignments are easier to optimize than others.
Registered users can post here. Sign in or register to post.
Pages: 12