yeah fair enough. that wasn’t really my point and I wasn’t paying attention
- 0 Posts
- 9 Comments
yeah it’s incorrect bc it destroys multibyte characters, butno idea what you’re saying about u8 being a different type from unicode. the original code was reading bytes and converting them too? the typing isn’t the issue, you can still store utf8 as a series of bytes
because with things that the compiler does, like padding for alignment, it frequently takes up more space than that. that was my argument the whole time. what til are you talking about? I’m talking about an extra layer you’ve decided doesn’t count. ofc sizeof bool will be a byte in all of those languages.
a bool taking up a single byte is a fantasy that those languages use because developers generally don’t need to think about all the other stuff going on.
brian@programming.devto Programming@programming.dev•What's your favorite IDE right now?2·3 months agofor some people it’s nice to start from nothing and build up config, I’d recommend doom for anyone else. it’s nice to be given a file with all the settings you can change instead of having to do it all yourself.
a bool is actually a single bit, the rest is all padding
c++ guarantees that calls to malloc are aligned https://en.cppreference.com/w/cpp/memory/c/malloc .
you can call
malloc(1)
ofc, but callingmalloc_usable_size(malloc(1))
is giving me 24, so it at least allocated 24 bytes for my 1, plus any tracking overheadyeah, as I said, in a stack frame. not surprised a compiler packed them into single bytes in the same frame (but I wouldn’t be that surprised the other way either), but the system v abi guarantees at least 4 byte alignment of a stack frame on entering a fn, so if you stored a single bool it’ll get 3+ extra bytes added on the next fn call.
computers align things. you normally don’t have to think about it. Consider this a TIL moment.
sure, but if you have a single bool in a stack frame it’s probably going to be more than a byte. on the heap definitely more than a byte
things that store it as word size for alignment purposes (most common afaik), things that pack multiple books into one byte (normally only things like bool sequences/structs), etc
probably about the same as like vapor smoothing abs with acetone. I think pla has solvents that work too but they’re much nastier