3 Oct 2024 |
swrge | is this fine or not ? | 21:11:42 |
Elegantbeef | It's fine it just allocates 2^16 bits in static memory. What is RecvEvent ? | 21:12:15 |
Elegantbeef | The issue is when you do store the sets in a field | 21:12:27 |
swrge | type of event i receive over a socket, i probably should name that RecvKind tho | 21:14:00 |
Elegantbeef | I mean what are it's values | 21:14:10 |
demotomohiro | sizeof(set[int8]) == 32
sizeof(set[EnumWith8element]) == 1 | 21:15:41 |
swrge | @_discord_1196075973871943741:t2bot.io
RecvEvent* {.pure.} = enum
RecvDispatchedEvent = 0,
RecvClientHeartbeat = 1,
RecvClientDisconnect = 2,
RecvNeedReconnect = 4,
RecvError = 8,
RecvUpdate = 12 | 21:18:07 |
swrge | huh... | 21:19:02 |
Elegantbeef | set[int8] takes 256 bits | 21:19:18 |
Elegantbeef | 256/8 = .... | 21:19:23 |
Elegantbeef | which is why the cast did not work | 21:19:31 |
swrge | yeah | 21:19:37 |
swrge | i feel a lil stupid lol | 21:19:47 |
Elegantbeef | The fact RecvEvent does not just do 1, 2, 4, 8, 16 is an affront to sanity | 21:20:33 |
demotomohiro | EnumWith8element in that code is supposed to be simple enum, but your RecvEvent is holey enum. | 21:20:44 |
Elegantbeef | Your method is pretty much the lowest CPU runtime one can do 😄 | 21:21:11 |
swrge | whoosp lol | 21:21:23 |
Elegantbeef | It's O(1) but takes up 2^16 bits | 21:21:27 |
swrge | I don't really understand the holey enum thing | 21:22:16 |
demotomohiro | echo sizeof(set[int8])
type
En = enum
A,
B,
C,
D,
E,
F,
G,
H
RecvEvent* {.pure.} = enum
RecvDispatchedEvent = 0,
RecvClientHeartbeat = 1,
RecvClientDisconnect = 2,
RecvNeedReconnect = 4,
RecvError = 8,
RecvUpdate = 12
echo sizeof(set[En])
echo sizeof(set[RecvEvent])
Result:
32
1
2 | 21:22:16 |
swrge | oh ok | 21:22:32 |
swrge | so im wasting space | 21:22:38 |
demotomohiro | If enum members have discontiguous numbers, it is a holey enum. | 21:23:34 |
swrge | yeah i just didnt understand at first you meant i was taking up more space | 21:24:20 |
swrge | than necessary | 21:24:26 |
swrge | i'll keep that in mind, im not bothered too much by this tho | 21:25:55 |
swrge | ty everyone ! | 21:26:11 |
| holy5300 joined the room. | 22:46:49 |
4 Oct 2024 |
| lfghs joined the room. | 01:55:49 |
| scorngyworngy joined the room. | 03:12:51 |