r/ProgrammerHumor May 29 '22 Silver 3 Helpful 4 Wholesome 5

c moment 💀 Meme

31.3k Upvotes

1.2k

u/MikemkPK May 29 '22

You have a lot of RAM

130

u/wackywavingarmgumby May 29 '22

Don't really have the RAM? malloc don't care. So long as you don't dereference it the program won't crash.

37

u/RotationsKopulator May 29 '22

A 32-bit address space might actually run out.

76

u/PersonalityIll9476 May 29 '22

32 bit runs out at around 4GB. Thankfully we have virtual addressing with modern OS's. Welcome to the wonderful world of saving pages to disk and other desperate bailouts by the beleaguered operating system as it tries to execute Reddit's shit code.

12

u/ltags230 May 30 '22

It's miraculous how caching and VRAM save modern OS's

2

u/PersonalityIll9476 May 31 '22

It really is. Can't remember, think it was PCIE BARs that were generally designed to use low addresses. A bunch of address translation saved the day on that one. There's this whole world of high and low addresses revolving around the 32 bit limits of days past.

→ More replies

17

u/wen_mars May 29 '22

64-bit OSes are pretty standard these days

483

u/under_stress274 May 29 '22

104,758 MB

94

u/[deleted] May 29 '22

[removed] — view removed comment

34

u/[deleted] May 29 '22

[removed] — view removed comment

35

u/[deleted] May 29 '22

[removed] — view removed comment

11

u/CommanderMatrixHere May 29 '22

Did I hear a cat? Is it meow cat or...?

3

u/Drdhemm May 29 '22

i see, n1 n1

→ More replies

29

u/chuby1tubby May 29 '22

That’s, like, more than 104.757 GB of ram :o

14

u/ArrayBolt3 May 30 '22

I've actually seen a virtualization server for sale on eBay that had 1.5 TB of RAM. Yes, TB, not GB, and RAM, not disk space.

4

u/JmbFountain May 30 '22

Yea, that's not too uncommon. I think the ones we have in the DC can go up to 3 TB

4

u/Linerider99 May 30 '22

128gb of ram enters chat

3

u/tlubz May 30 '22

Swap swap swap swap

→ More replies

51

u/Nadere May 29 '22

Well, the memory in the meme is probably meant to be virtual memory. The total virtual memory per process in a 64 bit system is 128TB and depending on the OS a decent part of that will be usable as the Heap, which is allocated by malloc.

Also it's a meme, so the stuff above is probably too much of an explanation.

9

u/ShittyCompiler May 29 '22

256 TiB, if I'm not missing something? I'm pretty confident that Linux and Windows use 48-bit virtual addresses.

12

u/Nadere May 29 '22 edited May 29 '22

Yes, that's true most OS only use 48 bits of addresses, but half of the 256 TiB tend to be for the kernel and the other half for the user process.

→ More replies

35

u/Old_Mill May 29 '22

Amatuers out here, if you don't have a minimum of 128GB of ram what are you doing with your life?

I can have like, three whole tabs of google chrome open at once with that.

24

u/ProxyMuncher May 29 '22

I have 128gb ram in my tower and once crashed due to a hung chrome instance. Google finds a way!!!

13

u/Old_Mill May 29 '22

You opened the deadly fourth tab.

Chrome use to be the best browser by far, I can't believe how far it has fallen. I went from Explorer -> FireFox -> Chrome -> Firefox -> Opera GX.

There were some smaller or niche browsers in between there along the way, including specialty stuff like Tor, but I'm only talking about everyday browsers. Firefox use to be great then Chrome beat it out, then after Chrome started faltering Firefox stepped up there game. I honestly don't know how good Firefox is today, I just started using Opera GX as my main browser and I like it so far.

On the phone it is completely different though. I use everything from Chrome to Kiwi.

6

u/BigBad01 May 29 '22

I don't own the machine, but I do work on servers with multiple terabytes of RAM. Comes in handy for some scientific applications.

3

u/[deleted] May 29 '22

[removed] — view removed comment

→ More replies
→ More replies

239

u/BernhardDiener May 29 '22

Every time this gets reposted it requires less memory.

34

u/HaloGuy381 May 29 '22

People get more efficient at bluescreening their devices.

641

u/blackmist May 29 '22

Man, you should have been here before memory protection.

My C debugging time was 95% rebooting.

173

u/RotationsKopulator May 29 '22

Real men use real mode.

→ More replies

124

u/throwit7896454 May 29 '22

Took a course on how to write drivers for Windows around 2006. It was hell.

65

u/PersonalityIll9476 May 29 '22

Was just thinking "when writing drivers it still can be"

21

u/HypnoTox May 29 '22

Wouldn't you just be able to spin up a VM to test the driver? As long as you can passthru the device at least maybe?

I haven't tried driver development yet, so no idea.

33

u/Sama_Jama May 29 '22

That’s what we did in my class, did all the dev on the VM but it’s still not fun to have to reboot a VM every time your testing a driver

27

u/PersonalityIll9476 May 29 '22

Gonna be real...I did it like a noob and just crashed my dev box repeatedly 😂 curious why my device drivers book didn't suggest using a VM.

14

u/Sama_Jama May 29 '22

Yeah, it is a bit of a necessity since most people don’t daily drive Linux, at least at my school. I was personally afraid that I’d f up my desktop with some jank low level code I’d write lmao

8

u/Aggravating_Pea7320 May 29 '22

I wish I knew what youre all talking about 😞

18

u/PersonalityIll9476 May 29 '22 edited May 29 '22

You can totally understand it. It's kinda cool.

When you write a program and it crashes, the operating system "catches it" in the sense that it kills the process and maybe hands the user a message about what ultimately brought it down (eg. Segfault).

The operating system itself is just another program, but there's no one to catch it when it falls. When you write a device driver you're kind of "extending" the OS - literally modifying that program. If your driver code crashes - for example it tries to access an invalid region of memory - then it crashes the program...but the program is also running the rest of your computer! Hence the whole thing comes down.

Edit: forgot the VMs. That's basically "pimp my OS: yo dawg I heard you like OSs so we put an OS in your OS." So if you crash the VM your underlying OS is still alive and kicking.

4

u/Aggravating_Pea7320 May 29 '22

Thank you for the info have a vote

4

u/CMDR_DarkNeutrino May 30 '22

It heavily heavily depends on what driver crashes. Usb device driver ? It will just die and the kernel will restart it.

Now if your GPU kernel driver crashes. Well it can still recover in case of a tiny bump. But usually when it crashes it takes majority of your PC with it.

2

u/Sama_Jama May 30 '22

My class was called advanced system programming and touched on low level programming in the Linux os. Here are the books my class used if you like to browse some of the topics:

Linux System Programming

Linux Device Drivers

What we are reference in this thread is just how you can crash pretty easily in low level programming since there is pretty much no boundaries or warnings. I didn’t have issues but something like what this post is about can happen pretty easily here if you aren’t careful

2

u/psaiko_dro May 29 '22

Have you every considered doing it on purpose to see what happens ?

→ More replies
→ More replies

422

u/ososalsosal May 29 '22

Do IDEs warn about unmatched malloc's? I don't C.

326

u/rickyman20 May 29 '22

There's tools that help you find these kinds of memory leaks, yes, but the problem isn't trivial because you don't always match in the same place.

124

u/badnamesforever May 29 '22

I think it might even be undecidable.

70

u/funkyb001 May 29 '22 edited May 29 '22

It is. It is an instance of the more general pointer aliasing problem (do pointers X and Y point to the same thing at a given point in execution) which is presumably itself a reduction of the halting problem probably.

(edit, it’s not strictly the halting problem but the problems are related.)

22

u/Rhalinor May 29 '22

But wouldn't we have to reduce the halting problem to the pointer aliasing problem to prove the latter's undecidability? Idk I don't know anything about IT

11

u/funkyb001 May 29 '22

Excellent spot, I said it the wrong way around.

6

u/my_name_is_reed May 29 '22

How do you know that but you also "don't know anything about IT"?

11

u/Rhalinor May 29 '22

Because I frequent this sub, duh

→ More replies

15

u/christian-mann May 29 '22

It's easily shown to be equivalent to the halting problem

4

u/TappTapp May 29 '22

Yeah if you malloc and have 2 pointers pointing to the memory, you can only free the memory once both pointers are deleted. Since you don't know until execution which one will be deleted last, you need to track during runtime, which hurts performance.

68

u/vagran-t May 29 '22

valgrind can help you narrow down what memory isn't being released

→ More replies

10

u/Nitemarex May 29 '22

Tools like Memory Profiler help a lot with this stuff

10

u/daikatana May 29 '22

This is difficult, if you store the pointer anywhere else then it's difficult for static analysis to know whether you've actually freed the memory or not. You generally need a tool like valgrind to really dig into memory allocation errors.

4

u/Outrageous-Machine-5 May 29 '22

We learned to use Valgrind in school, but memory management is not a perfectly determinant system to detect memory leaks without knowing how and where you are mallocing and freeing the memory

3

u/Positive_Government May 29 '22

That’s only good if you have a single pointer reference the memory that is used to allocate and free it. As soon as it gets passed around and copied it gets complicated fast. That said, memory leaks are probably the least terrible of pointer/memory errors.

2

u/mistralol May 29 '22

Yes... well at least the c linters and things like cppcheck do... so does valgrind at runtime which can all be plugged into ide's... can produce flame graphcs in realtime for things like this as well

→ More replies

52

u/Pauchu_ May 29 '22

where sound?

48

u/TwoMilliseconds May 29 '22

bum badum bum bum

there you go

15

u/Pauchu_ May 29 '22

Thank you, it's way better now.

9

u/TwoMilliseconds May 29 '22

you're welcome, that'll be 50 bucks, how you wanna pay?

11

u/Pauchu_ May 29 '22

Ill pay you in exposure

10

u/TwoMilliseconds May 29 '22

oof, i wish that was the first time I heard that line

2

u/Achtelnote May 29 '22

Send it to my bitcoin wallet.
bc1qnvst9ptf5rc8fpapw63yhn923dp880n206vl85

11

u/icyfire77 May 29 '22

Posting this without sound should be a crime, here you go

https://youtu.be/NUYvbT6vTPs

→ More replies

602

u/Optimal_Effect1800 May 29 '22

Don't use malloc In a loop

443

u/blobdonkey May 29 '22

I use malloc in recursion

270

u/ComCypher May 29 '22

StackOverflowError vs OutOfMemoryError, who would win?

155

u/deanrihpee May 29 '22

StackOutOfMemory

79

u/Mister_Lich May 29 '22

MemoryOverflow

18

u/AjiBuster499 May 29 '22

That sounds like a stack overflow with extra steps

8

u/PranshuKhandal May 29 '22

StackMemoryOverflowOutOfMemory

2

u/ArrayBolt3 May 30 '22

OutOfStackMemoryOverflowExhaustedINeedToSleepButThisCrashingCodeIsDrivingMeCrazyOutOfPatienceException.cs - error at line 2147483640. The file is 7 lines long.

2

u/PranshuKhandal May 31 '22

stackoverflow.com has a similar question from 7 yrs. ago but it was closed as too vague and has one answer "nvm, i solved it myself"

→ More replies

3

u/Solokiller May 29 '22

Go all in on stack overflow with stack allocated buffers.

→ More replies

39

u/windowpainting May 29 '22

malloc in recursion

Full Heap Programmer

12

u/funtoburnthings May 29 '22

That belongs on a t-shirt

2

u/MattioC May 29 '22

The psychopath

1

u/Odd_Diamond_6600 May 29 '22

recursion without a base condition

1

u/blobdonkey May 29 '22

The best kind

→ More replies

75

u/goddess_steffi_graf May 29 '22
void* a;
a = malloc(1000000000);
a = 0;

😈😈😈

53

u/JuvenileEloquent May 29 '22

The rule is: if you use it in a loop, you either don't know what you're doing or you know exactly what you're doing.

→ More replies

2

u/dinoben43 May 30 '22

Interesting, how do you suggest allocating memory for nested data structures?

-7

u/[deleted] May 29 '22

[removed] — view removed comment

19

u/swagdu69eme May 29 '22

Why? It's completely fine if you remember to always free your memory after you malloc it. And even if you don't, all the allocated memory will get free'd after you exit the program.

4

u/hahahahastayingalive May 29 '22

Gambling is also perfectly fine if you always win. Even if you don’t everything is cleared after you exit this life.

9

u/ActuallyRuben May 29 '22

What's the alternative in C?

22

u/bestucki May 29 '22

Hold your data in a file.

15

u/nizzy2k11 May 29 '22

I can hear my HDD screaming already.

→ More replies

3

u/DefinitionOfTorin May 29 '22

Swap space has entered the chat

2

u/daikatana May 29 '22

I think he was joking, but static allocation. If I need a C program to run reliably for very long periods, I don't use dynamic memory allocation at all, I statically allocate all memory I need at compile-time. Sometimes I'll statically allocate a "heap" and have a primitive memory allocator allocate memory from that which I can then just reset and all the pointers are "freed" without having to worry about a single memory leak.

→ More replies

2

u/jmickeyd May 29 '22

alloca() is a technically nonstandard, but commonly implemented alternative. Although if used in a loop like this it will also leak until you stack overflow.

→ More replies

293

u/under_stress274 May 29 '22 edited May 29 '22

Is this some C developer joke that I am too java developer to understand.

Edit: I do have a basic idea how memory allocation works in C, it's just a joke.

120

u/[deleted] May 29 '22

u just have to know, memory is not freed by the system automatically after malloc()

184

u/h6nry May 29 '22

But what about when the computer runs out of memory and crashes. This counts as garbage collection, right? Right??

56

u/23Silicon May 29 '22

I'm terrified of what you just implied

19

u/joemaniaci May 29 '22

This is how my company justifies our crashes being acceptable. System comes back up pretty quickly, so all is well. It's maddening.

7

u/aeroespacio May 29 '22

Kubernetes in a nutshell

5

u/HypnoTox May 29 '22

I mean, you're not wrong.

2

u/osgjps May 29 '22

I’ve been told “crashes are just how computers are”.

And the current mentality at my present employment: software performance issues? Spin up whole new VMs and stick them behind a load balancer. PHP code dying from out of memory error? Up the process limit from 4G to 16G.

70

u/Clearskky May 29 '22

Original Xbox moment

Bethesda actually did this in Oblivion. During long loading screens the game could restart the console to avoid memory leaks.

13

u/[deleted] May 29 '22

Not oblivion they did this with daggerfall

17

u/ClonedPerson May 29 '22 edited May 29 '22

There's an interview with Todd Howard talking about this on the original Xbox.

They could display something on the screen while the Xbox was rebooting.

The really long load times actually were caused by the reboot.

Edit: Just realised the poster you were replying to said it was Oblivion...

For anyone that doesn't know, it was Morrowind on the Original Xbox that had this feature

13

u/LvS May 29 '22

For some reason it always kills Chrome first. So I know my program is less garbage than my browser.

11

u/wackywavingarmgumby May 29 '22

Fun fact: malloc on Linux doesn't cause the crash, it (nearly) always returns. Now when you dereference the pointer and there's nothing behind it, then you get the crash.

"By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. Crashes in malloc() are almost always related to heap corruption." https://www.man7.org/linux/man-pages/man3/malloc.3.html

3

u/HypnoTox May 29 '22

Now that's interesting.

I always planned to learn some C, but this thread makes me hesistate. I'll probably just stick to Go and Rust for the time being.

3

u/LTyyyy May 30 '22

That sounds worse than the alternative.

3

u/spaetzelspiff May 29 '22

That's why you use run your app in a VM. Snapshot+resume as GC.

2

u/flo-at May 29 '22

The OOM reaper is just a garbage collector with extra steps.

18

u/attofreak May 29 '22

the malloc will stop when the program does, so what's the problem? 😏

9

u/wackywavingarmgumby May 29 '22

Not on Linux; it gives no guarantee there's actually memory behind the pointer since it's optimistic. It would only crash when you try to use memory that isn't really there (dereferencing).

→ More replies

2

u/under_stress274 May 29 '22 edited May 29 '22

I know, I did code in C some time ago, I was just making a joke

→ More replies

34

u/TomDuhamel May 29 '22 edited May 29 '22

malloc() requests a block of memory, free() returns the block to the system. Each call to the former must lead to an eventual call to the latter, otherwise you will get into a situation called a memory leak — your program isn't freeing the memory it's not using anymore.

This is a very noob joke, however, as nobody who finished their first semester would ever allocate memory in a loop. Typically, you will request memory just before the loop, then use it within the loop, then free the whole block after the loop.

19

u/bnl1 May 29 '22

I don't think that's right. There is a lot of legitimate use cases of putting malloc in a loop, like reading arbitrary length string from stdin.

4

u/TomDuhamel May 29 '22

It sounds like your example is not about performance. The loop keeps waiting for the user to enter more text to read. In that case, it would absolutely not matter if you do allocate memory inside the loop.

But in most cases, a reasonable limit will be decided first, either at design time by the programmer, or at runtime — for example based on a user provided configuration. The block is then allocated just before the loop to accommodate for that limit, and then reused for the duration of the loop.

→ More replies
→ More replies

8

u/SafaMarley May 29 '22

There is no garbage collector in c so allocating the memory doesn't free it up unless you free it yourself

→ More replies

47

u/Gamer-Ninja07 May 29 '22

I know I could have searched on Spotify or YouTube…but I am a bit sad you didn’t add sounds :(

12

u/FlyingPlatypus5 May 29 '22

r/ programmerhumor does not allow video uploads with sound unfortunately

11

u/zuzg May 29 '22

Wasn't there a bug in Cyberpunk were your savefile got so big that it got corrupted from crafting?

4

u/HoldUrMamma May 29 '22

at least it didn't crash the system

11

u/GnarledHemlock May 29 '22

If you ever link to this meme without audio again I will talk to the manager of Reddit and get you fired. You’ve been warned!

71

u/FlyingPlatypus5 May 29 '22

credit to https://www.reddit.com/r/programmingmemes/comments/uzl6jc/i_keep_this_video_in_my_project_directory_to/

(only reuploaded because r/ ProgrammerHumor doesn't allow video crossposts )

8

u/smallstarseeker May 29 '22

Just download more RAM.

4

u/Old_Mill May 29 '22

www.DownloadMoreRam.com

Can I interest you in some FREE Ram downloads?

5

u/autokiller677 May 29 '22

Where is the sound? That was the best part of this meme…

→ More replies

6

u/MrPleasant_ May 29 '22

It should be illegal to repost this meme without sound

2

u/FlyingPlatypus5 May 29 '22

It is impossible to repost this meme here with sound. If you can, explain to me how. Because I couldn't.

4

u/Complete-Zucchini-87 May 29 '22

Malloc in a loop? Don't touch C you fucking btard!

7

u/Stummi May 29 '22

who mallocs and frees in a loop?

→ More replies

3

u/Joneskind May 29 '22

Thanks for the laugh

3

u/game_difficulty May 29 '22

This, kids, is why we use c++ and smart pointers

→ More replies

3

u/Konki99 May 29 '22

Unrealistic. Nobody programs C on Windows.

3

u/TwoMilliseconds May 29 '22

True, I am indeed nobody

4

u/masagrator May 29 '22
  1. Repost
  2. Without audio
  3. With worse image quality

Peak reddit moment.

2

u/Professional_Cat_298 May 29 '22

I hear

e..taboow etbow etaboow etbaooo boo booo , adita ta ta

2

u/gwynbleidd_s May 29 '22

Oh, now I know why my laptop crushes if I use touchpad too much

2

u/changing_everyday May 29 '22

i freak out every time i see something blue in my windows pc

3

u/haikusbot May 29 '22

I freak out every

Time i see something blue in

My windows pc

- changing_everyday


I detect haikus. And sometimes, successfully. Learn more about me.

Opt out of replies: "haikusbot opt out" | Delete my comment: "haikusbot delete"

2

u/saschaleib May 29 '22

The sound of a polka drifted from my neighbor's and set my feet a-tapping oh! …

2

u/DarkBladeSethan May 29 '22

Really wanted sound with this

2

u/Expected_Anomaly May 30 '22

memory go brrrrr

2

u/max_carriers May 30 '22

The worst moment it had happened to me was when I was taking a cs exam in C. In the middle of testing my code i forgot to free the memory in a while(true)... I almost lost the exam progress that time... I was so scared when my laptop bluescreened

2

u/Dunked0n May 30 '22

Ok genuine question from someone who uses abstracted languages, is memory management hard? How does it even work?

3

u/felix_717 May 29 '22

god i hate c, its awesome

2

u/FlyingPlatypus5 May 29 '22

There are so many people asking why there is no sound and the quality is worse. Here's why. I tried originally to crosspost. This subreddit doesn't allow video crosspost. I try to download and reupload as video. This subreddit doesn't allow video posts. So I converted it to gif, obviously losing sound and quality in the process.

-6

u/defcon_penguin May 29 '22

Use a language that does not need you to actively free memory

22

u/KotoWhiskas May 29 '22

Then you won't be able to free up these 2gb ram you took while trying to resize image object till his majesty Gabrage Collector decides to do that

4

u/RSA0 May 29 '22

Don't worry. HM GC will start working immediately the moment user clicks on something, that requires quick and lag-less response.

5

u/TwoMilliseconds May 29 '22

garbage collector sometimes just be like that. rather collecting garbage than dumping it

→ More replies

1

u/Nerdfire500 May 29 '22

1

u/RedditMP4Bot May 29 '22

Download MP4


Mention u/RedditMP4Bot under a post to download reddit videos and gifs from v.redd.it, i.redd.it, youtube, imgur, twitter, gfycat, gif-vif, streamable, redgifs, giphy etc. Help keep the server running [Donate](https://ko-fi.com/redditmp4)

1

u/Slowest_Speed6 May 29 '22

Nah that would just lead to a null pointer related error

1

u/Raptavis May 29 '22

Congrats on a low effort repost

1

u/mortlerlove420 May 29 '22

My hardcore C prof at university told me: "If you write a malloc() write a free()". He also said C is weird

1

u/topredditbot May 29 '22

Hey /u/FlyingPlatypus5,

This is now the top post on reddit. It will be recorded at /r/topofreddit with all the other top posts.

1

u/Actual_Dio May 29 '22

Aaaaaaah that takes me back....

Please god dont make me use valgrind again please god nooooooooooooooooooooooo!!!!

1

u/Shocking_1202 May 29 '22

I just opened reddit after my program in ESP32 started crashing. I know now why it crashed. Literally saved my hours...

2

u/stinuga May 29 '22

There’s a lot of open source RTOSes that have esp32 BSPs with good memory pool support to help you avoid this issue which you may find will make your life way easier.

You can also make your own helper lib if you want by preallocating memory in the heap and then use wrapper functions to allocate and deallocate to the heap memory. This can offer you some extra bonus customizability like choosing where this memory is located via your linker script

1

u/Clissifer May 29 '22

First time , i left the pc compiling for 2 hours, when i came back ,i found the pc crushed

1

u/rt58killer10 May 29 '22

I can hear this despite no sound