*tink tink tink*

*tink tink tink*
AHEM
FUCK CUSTOM MEMORY ALLOCATORS AND FUCK C

Attached: Screenshot from 2019-04-23 21-24-37.jpg (1280x720, 210K)

>return (size_t)NULL;
You obviously come from the easy languages that hide everything from you. Go back to JavaScript or Python or whatever hellhole you crawled out of.

How do I know this?
Because
>#define NULL ((void*)0)
Which means you're doing
>return (size_t)((void*)0);
You're converting an integer to a pointer, then back to an integer, in the same fucking statement.

Attached: oC344ws.png (230x219, 7K)

Oh, and
>Visual Studio Code on vanilla Ubuntu
I hereby crown you king of noobs.

That assignment is actually really easy if you read the documentation and aren't a complete dumbfuck.

you know how i know you're a shitty programmer (who's trying to act smart)?
NULL could be defined differently, depending on platform. OP's code is guaranteed to work cross-platform, and you're shitting on him for it. Your fucking retarded code is only guaranteed to work on the platform you're building on. nice job, retard.

Hi OP, nice try.
>You're using a preprocessor constant exclusively defined for use with pointers as a zero value for an integer type
>Ooh more portable
It's exactly as portable as the literal 0, no more, no less. The *only* reason someone would use NULL like that is if they're retarded. Yeah, in C++, NULL is typically:
>#define 0
But in C, it's typically (void*)0.

NULL was never, ever meant to be used that way, and even if you're on a platform where it's defined as zero, it's still far less clear than just "return 0;". I bet you think you need to explicitly cast between integer types too.

Why am I being so hard on you, you wonder? Because you're shitting on a language that you clearly don't understand and pretending you have valid experience, when in truth you're just too much of a brainlet to write basic data structures without segfaulting over and over again.

Attached: 9sjsB3Y.png (231x218, 4K)

I get how to do it but the skeleton code and "test cases" (ie shell scripts and abusing grep) we got to work with are janky and overcomplicated.

Exactly why I did it that way. It's running on a remote Arch VM running on God knows what hardawre through two layers of SSH and will be pulle doff Git and evaluated on machines that are nothing like what I have at home.

If you're not optimizing everything for cross-platform compatibility in that scenario you're gonna get fucked. I've had it happen before and it's debugging hell.

first fit linked lists are the crappiest allocators to run and easiest to write
put asserts everywhere and make some check_consistency function, catch bug early

It's completely pointless to do that. A zero constant is always zero.

Attached: WzqVKjp.png (645x729, 90K)

There were originally asserts but they caused a weird bug with infinite allocations so i just replaced them all with if statements that check for NULL.

Forgot to add this happened to everybody and it's what we were told to do instead.

What do you mean by check consistency?

>shotgun programming in C
lovely

I see OP has gone silent after talking to himself and making up BS reasons.
Confess your ignorance. Admit your sins, and be purified.

Attached: SPNhGqn.jpg (720x576, 41K)

>NULL could be defined differently, depending on platform.
If NULL is defined to be anything except zero, this code fails. The function returns a size and if NULL is not zero, it's a positive number, and you are saying something with no size has a size.

Is there any CPU or OS where NULL is not 0 anyway?

Probably not. In a literal sense, yes, there's platforms where the bit representation of a null pointer is not zero. But the C standard mandates that assigning 0 to a pointer produce the null pointer value.

what worked for me was to have a liked list of all used pages/regions which was not used during normal alloc/realloc/free procedures (unless page was being freed or obtained) and allowed me to access all used memory in a different way than iterating over the list of free space.
Then check if no cycles, if all free space is in list, if everything is only being pointed to once, etc.
Qlso canaries at the start and end of pages to detect overflows and corruptions. But segfaults do similar, I was on system without virtual memory.

it's on compile time anyway, who cares

It's extremely bad form and demonstrates a very deep ignorance of the language.

>fuck custom memory allocators
yes; so why are you doing that?

Because it's one of the most common projects assigned in any advanced C or operating systems class.

The one before that was a custom shell.

Neither one is bad in the most basic forms but the versions I had to do required a ton of extra functionality like memory visualization, multiple allocation algorithms, pipes/redirects and a bunch of history command functionality for the shell and thread safety for the allocator.

no, you are just nitpicking over irrelevant detail

a 0 is a 0 no matter in what way it is typecast. The only reason you even typecast in C is so the compiler doesn't complain.

You don't convert anything in C, you just tell the compiler "yes, I intended to pass this". casting NULL to size_t isn't that cool, yeah, but it doesn't have any impact on performance whatosever, nor is it prone to errors.