[ home / overboard ] [ date ] [ soy / qa / raid / incel ] [ int / pol ] [ a / biz / fit / mtv / r9k / sude / tech / v / x ] [ q / news / chive / rules / pass / bans / status ] [ booru / wiki ]

A banner for soyjak.party

/pol/ - International /Pol/itics & /Bant/er

Politics & countrywars
Catalog
Name
Email
Subject
Comment
Flag
File
Password (For file deletion.)

File: 1794406188957i.jpg 📥︎ (62.85 KB, 900x1200) ImgOps

 â„–4423614[Quote]

Can someone explain use cases of malloc() in C? why not just assign the value to the variable?

 â„–4423626[Quote]

it allocates memory for autistic retards who have nothing more interesting to do than learning a dnb language in the age of ai

 â„–4423631[Quote]

like why would you for example use:
int *p = malloc(sizeof(int));
*p = 67;
when you can just:
int i = 67;
int *p = &i;
???

 â„–4423637[Quote]

>*p
OYYYYY

 â„–4423639[Quote]

>>4423626
I want to learn it for cybersecurity and stuff

 â„–4423641[Quote]

>>4423631
you'd know a lot about 'p avatar fagging as 15 year old girl

 â„–4423642[Quote]

File: 1793989782484u.jpg 📥︎ (50.22 KB, 509x680) ImgOps


 â„–4423654[Quote]

File: 1795621929068t.jpg 📥︎ (35.23 KB, 496x680) ImgOps

>>4423631
guys explain pls!!!!!!!!

 â„–4423657[Quote]

you use malloc when you need to allocate memory on the heap. Memory regions on the heap can be shrunk, expanded or relocated. Memory on the stack is continuous.

 â„–4423658[Quote]

File: gem.gif 📥︎ (2.79 MB, 498x280) ImgOps

>>4423639
>learning c for cybersec
another useless reverse engineer nigger indie game cracker lowlevel fan basement dweller

 â„–4423662[Quote]

>>4423657
You need an array with dynamic size? Heap will suffice.

 â„–4423664[Quote]

>>4423658
Well what are your suggestions then?

 â„–4423666[Quote]

>>4423664
don't listen to the femboy faggot.

 â„–4423670[Quote]

File: 1796000331497k.jpg 📥︎ (15.22 KB, 541x410) ImgOps

>>4423657
idk what a heap is lol
its like a data structure or something

 â„–4423676[Quote]

File: ggg.gif 📥︎ (7.08 MB, 400x485) ImgOps

>>4423664
joining lockbit and using their binaries instead of writing your snca harmless niggerware on (bb)C

 â„–4423679[Quote]

>>4423676
a joke btw don't do dat

 â„–4423680[Quote]

>>4423670
When your program starts, operating system allocated pages to it, usually like several kilobytes. Your program uses this memory for .text (code that is executed), .data (global variables) and other sections, but there's also a stack and a heap. Stack is fast to access, I cannot remember why doebeit, maybe because it's in CPU cache. Heap is slower.

 â„–4423681[Quote]

File: 1791998256215d.jpg 📥︎ (87.59 KB, 1080x1080) ImgOps

>>4423676
Well I want to learn how computers work on lower level
After I finish learning C I want to know the basics of assembly

 â„–4423684[Quote]

>>4423681
good luck then applying this useless knowledge somewhere

 â„–4423686[Quote]

>>4423680
Ok so malloc is used for like arrays and strings so that their size can later be changed am I getting it right?

 â„–4423690[Quote]

Actually I'll ask my Chatgpt I got a free premium for a month

 â„–4423692[Quote]

>>4423680
When you call malloc, it calls your operating system under the hood. It tells OS this
>hey, I need some dynamic memory! Gimme some
<k here's like 2 KB
>2 KB? I need way less! Like 256 bytes
and here comes the allocator part. It shrinks this memory to 256 bytes, writes some metadata outside of it, so that it won't have to call OS the next time, and volia. You have 256 bytes.
>>4423686
well correct. But C strings are allocated on the static memory, usually. Try doing this:
char* ptr = "string"
*ptr = 'a'
it will give you an error, because ptr points to non-writeable data.

 â„–4423696[Quote]

File: 1794270756659p.jpg 📥︎ (21.98 KB, 428x540) ImgOps

>>4423692
Ok i need to learn about how memory works

 â„–4423698[Quote]

Using heap is like putting your cock inside a mouse trap, though. The pointer may expire after some realloc() call, or you may just forget that you freed some shit.

 â„–4423713[Quote]

>>4423698
I remember when I was writing a simple runtime, that would keep objects of several size close to each other. Foolish was I. I had to battle with the allocator because I like a retard, tried to keep memory continous, using clever pointer arithmetic, but realloc() would relocate my shit, which would lead to a program crash at unknown time.

 â„–4423726[Quote]

>>4423681
why the fuck do you need to learn assembly. Nigga are you going to create boot sector programs? Or EFI PE executables?

 â„–4423749[Quote]

>>4423681
I want to learn assembly to make another rollercoaster tycoon game or something like that



[Return][Catalog][Go to top][Post a Reply]
Delete Post [ ]
[ home / overboard ] [ date ] [ soy / qa / raid / incel ] [ int / pol ] [ a / biz / fit / mtv / r9k / sude / tech / v / x ] [ q / news / chive / rules / pass / bans / status ] [ booru / wiki ]