Programming thread

The java memory management system totally sucks I have no clue why anyone would defend it

Did they accidentally swap from an alternate timeline where enterprise software is actually good or something?
allocating 15000 gc objects and then seeing them getting freed in a big chunk is about as slow as malloc()ing those same 15000 objects and manually free()ing them when they fall out of scope
except the gc will actually work better in this scenario because it can do things like defragment the memory
Re: memory usage sawtooth graphs, what do people imagine a memory usage graph should look like? That's the pattern of dynamic memory usage, a bunch of stuff gets allocated and eventually falls out of scope and are (or should be) cleaned up. But I suppose it's just the magical thinking of retards imagining that somehow freeing memory costs nothing when a human does it and everything when a runtime does.
just because the sawtooths are microscopic with malloc() doesn't mean they don't exist
People loved to blame the performance on Java and GC back in the day, but as far as I know the actual issue was the renderer, which used the ancient OpenGL 1 and did ridiculous shit like issuing a draw call for every block or so. Once the overhaul of the renderer landed (around 1.8?), performance got noticeably better. I'm not sure how you'd run specifically into GC issues in Minecraft either to be honest, outside of Java pointer soup being taxing in general.
True, but then Mojang started using immutable data-object classes for their basic Vector3f, BlockPos, Quaternion, etc. math structures, which were allocated en masse every single frame for every single mathematical calculation. I forget exactly which version this happened in, but I do remember it being a problem.
as always the real problem is the code that allocates 9 octillion vector3 on the heap
 
With GC, you can use object pools to cut down on repetitive short-term allocations of common objects. In my chat client, for example, I use Go's version of object pools (sync.Pool) for chat message objects. I only hold onto the most recent 512 messages, so I can just recycle ones that fall out of scope. Keep in mind pooling may be inefficient in some cases due to shit like fragmentation.
 
Last edited:
  • Like
Reactions: Wol
how does a piece of software become memory unsafe anyways?? like all these random vulnerabilities pop up all the time, but i literally don't understand how it happens, like, just use memory responsibly???
 
  • Thunk-Provoking
Reactions: y a t s
With GC, you can use object pools to cut down on repetitive short-term allocations of common objects. In my chat client, for example, I use Go's version of object pools (sync.Pool) for chat message objects. I only hold onto the most recent 512 messages, so I can just overwrite the fields of ones that fall out of scope. Keep in mind pooling may be inefficient in some cases due to shit like fragmentation.
this is a specific trick in the "use mutation so you don't have to allocate 60 gigabytes per second" class of gc-aware program optimizations
how does a piece of software become memory unsafe anyways?? like all these random vulnerabilities pop up all the time, but i literally don't understand how it happens, like, just use memory responsibly???
fully manual languages are often incredibly painful to do complicated data structures in and eventually you will end up making a minor mistake
but yes, if you avoid all UB in C programs they are guaranteed to be memory safe
the hard part is avoiding all UB

also i would like to note that this question follows a parallel line of reasoning to:
how does a piece of software have bugs anyways?? like all these issues pop up all the time, but i literally don't understand how it happens, like, just write it the right way???
it probably makes sense to think like this, until you try doing it, inevitably fuck up, and realize a fundamental truth:
Computers are Hard™
 
how does a piece of software become memory unsafe anyways?? like all these random vulnerabilities pop up all the time, but i literally don't understand how it happens, like, just use memory responsibly???
Managing lifetimes in a sufficiently complex program is no simple feat. Accessing a region of memory after it was freed (use-after-free) can severely fuck your shit up. If you leave a "dangling" pointer pointing to a freed region, that region is free to be re-allocated and overwritten with arbitrary data. If an attacker is skilled enough, he can put specially crafted data in one of these regions and have the program access specific chunks of it. A lot of damage can be done this way.
 
Last edited:
If you leave a "dangling" pointer pointing to a freed region, that region is free to be re-allocated and overwritten with arbitrary data. If you're skilled enough, you can put specially crafted data in one of these regions and have the program access specific chunks of it. You can do a lot of damage this way.
Is there a non-asinine way to safeguard pointers and avoid unwanted memory leakage like this? Such as "unless this pointer's contents is verified to not cause harm and it's actually not being used, zero it and use it", or is it bad for performance?

I can think of a way to minimize constant checking, such as a guaranteed memory boundary, but then I realize that's more the job of an OS than an userland application. Any thoughts?
 
Is there a non-asinine way to safeguard pointers and avoid unwanted memory leakage like this? Such as "unless this pointer's contents is verified to not cause harm and it's actually not being used, zero it and use it", or is it bad for performance?
this general idea is sometimes referred to as "garbage collection"
the "verified to not cause harm" step is typically done by tracing references from globals and stack items (aka "roots") until all items have been checked
then the collector does that "zero it and use it" thing you mentioned

note: certain compilers can statically trace certain lifetimes and eliminate gc'ed heap allocations (and rust makes a big fuss about how it forces you to use it for all dynamic allocations)
 
Is there a non-asinine way to safeguard pointers and avoid unwanted memory leakage like this? Such as "unless this pointer's contents is verified to not cause harm and it's actually not being used, zero it and use it", or is it bad for performance?

I can think of a way to minimize constant checking, such as a guaranteed memory boundary, but then I realize that's more the job of an OS than an userland application. Any thoughts?
There are tools to test for memory problems, such as valgrind. Of course, there's no guarantee you will catch them all in testing. Any sort of built-in protection/prevention measure is essentially just one or more of the other memory management paradigms (e.g. ref counting).
 
the only 2 ways to have true memory safety are to have an extremely autistic cbt compiler that has an entire book on how to properly make a linked list (rust) or [GC PAUSE] use the new [GC PAUSE] superniggerdouble3/4thspace[GC PAUSE]concurrentmarksweepjak collector that totally doesn't [GC PAUSE] have latency iss[GC PAUSE]ues
 
allocating 15000 gc objects and then seeing them getting freed in a big chunk is about as slow as malloc()ing those same 15000 objects and manually free()ing them when they fall out of scope
if you are managing it yourself:
- no jvm memory exhaustion forcing you to reconfigure memory allocated to it
- periodical GC doesn't ever fall behind object creation
- simpler

the supposed upsides of GC is its somewhat easier to make the program not segfault. can still leak like all getout just means some things have dangling references somewhere. not worth it
 
  • Dumb
Reactions: 306h4Ge5eJUJ
I think I've told this rant before, but... Python GC rant.
I worked for a customer who had an app which loaded a bunch of data into a Python process, forked a bunch of copies, each process doing work on some small part of the dataset, then returning the data(over file descriptors I think, whatever), and then exiting.

As we grew the dataset it started OOMing. But the copy on write semantics of fork() meant even with a ton of copies there should be no problems. Enter Python. All the processes take roughly the same amount of time. Python, before it exits does a GC pass. Each individual process then touches almost every page with a refcount or similar update. So instead of a small incremental memory use you now had n X full memory usage briefly, but for just long enough for it to go boom. As I recall the simple solution was to simply have each forked process disable GC so it wouldn't run on exit and all was 'well'.
 
no jvm memory exhaustion forcing you to reconfigure memory allocated to it
true, it usually does need a good bit of extra memory to work well, and java limiting the max heap is sort of weird
maybe, but do you actually really know how your modern malloc() implementation works? and do you really want to have the complexity of manually allocating and deallocating every single piece of memory you ever use, just to avoid the complexity of a weird algorithm that walks through your heap every now and then?
the supposed upsides of GC is its somewhat easier to make the program not segfault. can still leak like all getout just means some things have dangling references somewhere. not worth it
and it can do stuff like defragment the heap transparently and allocate and deallocate memory chunks faster than malloc in many scenarios
also the main benefit of gc is that you don't have to constantly think about lifetimes and can spend valuable brain power using more advanced data structures instead of fighting the computer
 
Used Coq as well albeit for formalizing mathematics specifically linear algebra. Wanted to try doing the same with C programs and was wondering if there are any good resources on that.
I like Coq for mathematics as well, but when it comes to programming language verification, the foundational (no pun intended) texts there are the Software Foundations series, specifically Volumes 2 and 5. From my experience most dedicated Coq courses at universities eventually go into DSL verification, and IIRC the INRIA developers themselves lean mostly into language verification instead of mathematics, with the latter being an independent effort by the academic community on top of the system. There is also CompCert, a formally verified compiler for (a significant subset of) C, which seems more directly related to your interest (source available though sadly not free software so beware)

Edit: something unrelated I wanted to sperg about; it really ticks me that practically no other formal logic system besides Coq is ASCII-only, or has a canonical ASCII representation. I guess it is to be expected of software geared towards mathematicians, with their soup of domain-specific syntax, but it really rubs me the wrong way that Unicode fonts can rarely be made to look good and uniform with monospaced fonts, and I have for years been dreaming of a formal logic system that feels like Lean but can be displayed on the dumbest terminals. Agda is, of course, the worst offender:
Rich (BB code):
-- agda-unimath snippet
unlabeled-structure-species-types :
  {l1 l2 : Level} (F : species-types l1 l2) → ℕ → UU (lsuc l1 ⊔ l2)
unlabeled-structure-species-types {l1} {l2} F n =
  Σ ( Type-With-Cardinality-ℕ l1 n)
    ( λ X → F (type-Type-With-Cardinality-ℕ n X))
(or just take a look at some pages of this), though at that point it kind of approaches the cool of APL, where you can imagine dedicated "Agda machines" with massive keyboards to accommodate all the extra legal characters
 
Last edited:
Im sure this has been asked a zillion times in this thread but I honestly want the farms advice on this.

I want to learn the fundamentals of coding and computer science. Im not intending on getting a coding job or making an app etc. I just want to make experimental logic programs and other weird shit. I want to learn C because its the simplest(as in least abstracted and pajeet-ified) language and it allows me to learn the fundamentals of how the computer actually works.

Are there any sites / books / videos etc. you would recommend for a person who has only ever coded an HTML webpage as a school project? My preference is for someone who actually explains the concept vs youtube niggers who just tell you to make some code without explaining what an Array or a Function actually is.
 
Im sure this has been asked a zillion times in this thread but I honestly want the farms advice on this.

I want to learn the fundamentals of coding and computer science. Im not intending on getting a coding job or making an app etc. I just want to make experimental logic programs and other weird shit. I want to learn C because its the simplest(as in least abstracted and pajeet-ified) language and it allows me to learn the fundamentals of how the computer actually works.

Are there any sites / books / videos etc. you would recommend for a person who has only ever coded an HTML webpage as a school project? My preference is for someone who actually explains the concept vs youtube niggers who just tell you to make some code without explaining what an Array or a Function actually is.
https://en.cppreference.com/w/c <- behold: the fucking manual (read it)
you also need some basic tutorials or whatever but i will leave that as an exercise to the reader (maybe try the newest edition of k&r or just find some tutorials or learn it by pulling apart nethack or something)
also if you didn't post this from linux, install it now, because advanced (libraries) c programming is infinitely easier on unix-like systems
if you are too PUSSY to switch, see: https://www.msys2.org/

also don't just learn c you should try many languages because lisp can teach you things that will make you a better c programmer and even java will teach you some things that c doesn't

note: the hardest thing about learning programming is getting over being a whiner retard who says "man i could never learn to program" and actually running the text editor and writing a program
 
https://en.cppreference.com/w/c <- behold: the fucking manual (read it)
you also need some basic tutorials or whatever but i will leave that as an exercise to the reader (maybe try the newest edition of k&r or just find some tutorials or learn it by pulling apart nethack or something)
also if you didn't post this from linux, install it now, because advanced (libraries) c programming is infinitely easier on unix-like systems
if you are too PUSSY to switch, see: https://www.msys2.org/

also don't just learn c you should try many languages because lisp can teach you things that will make you a better c programmer and even java will teach you some things that c doesn't

note: the hardest thing about learning programming is getting over being a whiner retard who says "man i could never learn to program" and actually running the text editor and writing a program

I'm planning to switch to Linux Mint because Windows is living proof we need Total Pajeet Death right now. I assume that distro is fine for coding purposes?
 
Back