Readit News logoReadit News
mandarax8 commented on C++ says “We have try... finally at home”   devblogs.microsoft.com/ol... · Posted by u/ibobev
winternewt · a month ago
Destructors are vastly superior to the finally keyword because they only require us to remember a single time to release resources (in the destructor) as opposed to every finally clause. For example, a file always closes itself when it goes out of scope instead of having to be explicitly closed by the person who opened the file. Syntax is also less cluttered with less indentation, especially when multiple objects are created that require nested try... finally blocks. Not to mention how branching and conditional initialization complicates things. You can often pair up constructors with destructors in the code so that it becomes very obvious when resource acquisition and release do not match up.
mandarax8 · a month ago
The entire point of the article is that you cannot throw from a destructor. Now how do you signal that closing/writing the file in the destructor failed?
mandarax8 commented on 4 billion if statements (2023)   andreasjhkarlsson.github.... · Posted by u/damethos
uplifter · 2 months ago
You're absolutely right. The obvious solution would have been to create a boolean table containing all the pre-computed answers, and then simply use the integer you are testing as the index of the correct answer in memory. Now your isEven code is just a simple array lookup! Such an obvious improvement, I can't believe the OP didn't see it.

And with a little extra work you can shrink the whole table's size in memory by a factor of eight, but I'll leave that as an exercise for the interested reader.

mandarax8 · 2 months ago
Maybe we can even find some correlation in the bit pattern of the input and the Boolean table!
mandarax8 commented on Shaders: How to draw high fidelity graphics with just x and y coordinates   makingsoftware.com/chapte... · Posted by u/Garbage
LoganDark · 3 months ago
Is the article about OpenGL? I see a few mentions of OpenGL in a section about graphics APIs that also mentions at least Vulkan, which doesn't automatically provide fragment coordinates, and WebGPU, which also doesn't. Shaders by default have no concept of fragment coordinates; it's OpenGL the API that introduces them by default.
mandarax8 · 3 months ago
The pixel position has to be known, how else are you rasterizing something?
mandarax8 commented on Apple M5 chip   apple.com/newsroom/2025/1... · Posted by u/mihau
coffeeaddict1 · 4 months ago
> an absolutely ancient OpenGL version

I still don't get this. Apple is a trillion dollar company. How much does it cost to pay a couple of engineers to maintain an up to date version on top of Metal? Their current implementation is 4.1, it wouldn't cost them much to provide one for 4.6. Even Microsoft collaborated with Mesa to build a translation on top of dx12, Apple could do the same.

mandarax8 · 4 months ago
Their current OpenGL 4.1 actually does run on top of metal making it even more blatantly obvious that they just don't want to.
mandarax8 commented on OpenGL: Mesh shaders in the current year   supergoodcode.com/mesh-sh... · Posted by u/pjmlp
zackmorris · 4 months ago
A little bit off topic but: GL_LINES doesn't have a performant analog on lots of other platforms, even Unity. Drawing a line properly requires turning the two endpoint vertices into a quad and optionally adding endcaps which are at least triangular but can be polygons. From my understanding, that requires a geometry shader since we're adding virtual/implicit vertices. Does anyone know if mesh shaders could accomplish the same thing?

Also I wish that GL_LINES was open-sourced for other platforms. Maybe it is in the OpenGL spec and I just haven't looked. I've attempted some other techniques like having the fragment shader draw a border around each triangle, but they all have their drawbacks.

mandarax8 · 4 months ago
I'm not sure exactly what you mean, but you can both output line primitives directly from the mesh shader or output mitered/capped extruded lines via triangles.

As far as other platforms, there's VK_EXT_line_rasterization which is a port of opengl line drawing functionality to vulkan.

mandarax8 commented on Under the hood: Vec<T>   marma.dev/articles/2025/u... · Posted by u/r4um
arka2147483647 · 4 months ago
https://en.cppreference.com/w/cpp/container/vector/reserve.h...

says

> Increase the capacity of the vector (the total number of elements that the vector can hold without requiring reallocation) to a value that's greater or equal to new_cap.

I belive that the behaviour of reserve() is implementation defined.

mandarax8 · 4 months ago
That said MSVC,GCC and clang all implement it to allocate an exact value.
mandarax8 commented on Shipping WebGPU on Windows in Firefox 141   mozillagfx.wordpress.com/... · Posted by u/Bogdanp
pjmlp · 7 months ago
It is called middleware, no need to wait for WebGPU outside of the browser, with all the constraints of an API design targeted to browser sandboxes.
mandarax8 · 7 months ago
Can you point me to some good middleware then? I haven't been able to find any.
mandarax8 commented on Parameterized types in C using the new tag compatibility rule   nullprogram.com/blog/2025... · Posted by u/ingve
sim7c00 · 8 months ago
I dont know either.

int somearray[10];

new_ptr = somearray + signed_value;

or

element = somearray[signedvalue];

this seems almost criminal to how my brain does logic/C code.

The only thing i could think of is this:

somearray+=11; somearray[-1] // index set to somearray[10] ??

if i'd see my CPU execute that i'd want it to please stop. I'd want my compiler to shout at me like a little child, and be mean until i do better.

-Wall -Wextra -Wextra -Wpedantic <-- that should flag i think any of these weird practices.

As you stated tho, i'd be keen to learn why i am wrong!

mandarax8 · 8 months ago
Any kind of relative/offset pointers require negative pointer arithmetic. https://www.gingerbill.org/article/2020/05/17/relative-point...
mandarax8 commented on Bzip2 crate switches from C to 100% Rust   trifectatech.org/blog/bzi... · Posted by u/Bogdanp
guappa · 8 months ago
You know how the page cache works? Static linking makes it not work. So 3000 processes won't share the same pages for the libc but will have to load it 3000 times.
mandarax8 · 8 months ago
You can still statically link all your own code but dynamically link libc/other system dependencies.
mandarax8 commented on Simplest C++ Callback, from SumatraPDF   blog.kowalczyk.info/a-sts... · Posted by u/jandeboevrie
kjksf · 8 months ago
I can honestly say that I couldn't write that thing in 100 years.

I can't even read it.

That's the fundamental problem with C++: I've understood pretty much all Go code I ever looked at.

The code like the above is so obtuse that 0.001% of C++ programmers is capable of writing it and 0.01% is capable of understanding it.

Sure, I can treat it as magic but I would rather not.

mandarax8 · 8 months ago
Yeah it's a shame that to go from your idea to something that's 'general' (ie just some arbitrary arguments) you need to write this arcane garbage.

u/mandarax8

KarmaCake day141September 1, 2021View Original