#Pretty code

1 messages · Page 1 of 1 (latest)

heady garden
#

This code looks a bit weird to my eyes, just a quick question, is there a better way of doing this? (allocate something, use it, free it, in a chain)

#

This is what it looked like before, however it wouldn't free stuff until the end of the function

wild linden
#

wouldn't the first version be faster?

heady garden
#

faster? no

wild linden
#

why no

heady garden
#

freeing allocations after use? yes

heady garden
#

no changed order of operations, except for when it frees memory

slender sky
wild linden
#

ye but ur mixing in instructions no?

heady garden
#

each allocation is like 4 GiB

slender sky
#

I see

wild linden
#

thats like flushing out a buffer everytime you print something

wicked linden
#

don't use defer 🙃

slender sky
#

yeah, probably do want to free that immediately then lol

wicked linden
#

it's what i would do

#

idk

heady garden
#

if I don't use defer, that could work...

slender sky
#

yeah, gonna agree, basically what I would do

heady garden
#

except if a try fails, then the code after won't run

#

so it would leak memory

wicked linden
#

yea that's true

heady garden
#

eg.

  • allocate
  • try [failing fuction]
  • free memory
wild linden
#

does freeing involve any syscalls?

heady garden
#

idk, just using the page allocator here

wild linden
#

idk either

slender sky
#

usually

#

yes

#

unless it's an allocator like ArenaAllocator

wild linden
#

i mean you have to tell the OS that the memory is available

slender sky
#

or FixedBufferAllocator

#

or I guess, sometimes it doesn't get freed directly back to the OS

#

if it's GPA

#

and instead gets put into a freelist

#

at any rate

wild linden
#

ye I haven't measured the performance of freeing immediately

#

but I would use the buffer analogy

#

you usually want to do one thing at a time

slender sky
#

at any rate

#

I think your current code is fine enough

heady garden
#

ok thanks

wild linden
#

same here

heady garden
#

I'll stick with the tower for now

slender sky
#

if you wanted to make it look nicer, probably would have to abstract it into functions

heady garden
#

true lol

#

but then function spam

#

welp alright, I guess I'll close this question