this post was submitted on 31 Aug 2025
330 points (96.6% liked)

Programmer Humor

26175 readers
1032 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 

Finally I have a valid reason to learn about memory management. It was also hella weird when encountering it.

top 50 comments
sorted by: hot top controversial new old
[–] ulterno@programming.dev 16 points 6 days ago (1 children)

Back when I was a kid and was learning C, I used to wonder why people considered pointers hard.
My usage of pointers was like:

void func (int * arg1)
{
    // do sth with arg1
}
int main ()
{
    int x;
    func (&x);
    return 0;
}

I didn't know stuff like malloc and never felt the need in any of the program logic for the little thingies I made.
Pointers are not hard. Memory management makes it hard.

[–] chunes@lemmy.world 2 points 5 days ago

C makes them unnecessarily confusing in my opinion. In Forth they're as simple as can be compared to C.

[–] iAvicenna@lemmy.world 6 points 6 days ago (1 children)
[–] cows_are_underrated@feddit.org 3 points 6 days ago (1 children)

I did not knew this existed, so thanks for the tip.

[–] iAvicenna@lemmy.world 1 points 5 days ago

have fun (ノಠ益ಠ)ノ彡┻━┻

[–] favoredponcho@lemmy.zip 9 points 6 days ago

Valgrind to the rescue

[–] resipsaloquitur@lemmy.world 9 points 6 days ago (1 children)

RAII.

Can’t leak what never leaves the stack frame.

[–] CookieOfFortune@lemmy.world 10 points 6 days ago (1 children)
[–] resipsaloquitur@lemmy.world 7 points 6 days ago (1 children)

Classes are just pretentious structs.

[–] CookieOfFortune@lemmy.world 3 points 6 days ago (1 children)

How do you get destructor behavior in C?

[–] henfredemars@infosec.pub 2 points 6 days ago* (last edited 6 days ago) (1 children)

You call the destructor. It’s simply not automatically done for you with the concept of going out of scope.

Back when C++ was simply a text pre-processor for C, you could see these normal function calls. You can still see them in the un-optimized disassembly. There’s nothing magical about a destructor other than it being inserted automatically.

[–] entwine@programming.dev 2 points 5 days ago (1 children)

being inserted automatically.

Aka the entire point of RAII

[–] resipsaloquitur@lemmy.world 2 points 4 days ago

The point of RAII is that a resource is allocated and freed in the same scope.

You can free it with an explicit call to a destructor, an implicit call, or with memory allocated on the stack, just wait for the stack frame to be exited.

[–] diemartin@sh.itjust.works 5 points 6 days ago

It'll be fun when you get to funny errors because you used freed memory.

When I was learning about linked lists and decided to use them in a project, I "removed" items by making the previous item's next point to this item's next, except I misplaced a call to free before using the fields, and it somehow still worked most of the time on debug builds, but on optimized builds it would cause a segmentation fault 100% of the time.

[–] mhague@lemmy.world 1 points 6 days ago

Cruft can be a hard thing to debug. Mainly when you're not used to memory issues and haven't learned all the best practices.

There's also zig if you want to play with memory. You'll know a lot about allocation, that's for sure.

load more comments
view more: next ›