276
1
277
1
278
1
submitted 2 years ago* (last edited 2 years ago) by gulia@mastodon.social to c/cpp@programming.dev

Jack London once said, "You can't wait for inspiration. You have to go after it with a club". When it comes to game development, the SDL project may well be such a club. How is it made, though?

What bugs does SDL have? And what Sam Lantinga says about it?

https://pvs-studio.com/en/blog/posts/cpp/1081/

@cppguide
@cpp
@c_discussions

279
1
280
1
submitted 2 years ago* (last edited 2 years ago) by lawmurray@programming.dev to c/cpp@programming.dev

C++ trick I pulled today. Like an explicit constructor but context dependent. Any alternatives from folks who've needed to do similar? One thing I still need to dig into a little deeper is how copy elision behaves here.

281
1
282
1
283
1
submitted 2 years ago* (last edited 2 years ago) by rinsler@programming.dev to c/cpp@programming.dev
284
1
285
2

An excellent talk by Timur about type punning, the UB weirdness that accompanies it and attempts at doing something similar with modern C++ without UB (which led to std::bit_cast and other proposals) while revisiting notions like aliasing and alignment.

286
1
287
3
288
1
289
0
submitted 2 years ago* (last edited 2 years ago) by AlmightySnoo@lemmy.world to c/cpp@programming.dev

If you're writing code that's doing lots of memory allocations (e.g. lots of nodes being created in some huge graph at runtime and/or you're also doing lots of type erasure, and most importantly you can't know in advance how many you'll need) then you might wanna take a look at C++17's std::pmr instead of trying to write your own allocators (which is still a good idea if the goal is just to learn).

In particular, what would interest you the most are the memory resources themselves, which are in the memory_resource header file (https://en.cppreference.com/w/cpp/header/memory_resource ).

I had great success using in particular unsynchronized_pool_resource (perfect in single-threaded settings where you're sure you don't want other threads to access that resource) and monotonic_buffer_resource (perfect when you don't care about reusing previously freed memory and care more about speed, so that the cost of one allocation is then just a pointer increment inside a buffer and "deallocation" is a no-op) in our production code and, depending on the scenario, achieved speedups between x2 and x3 compared to using the standard allocator.

You can directly use the .allocate and .deallocate member functions of those resources (although the semantics will be a bit different from your usual malloc and free, as you need to remember the alignment and the size of the allocated space when you want to deallocate). You also have standard containers inside std::pmr that can be bound to one of those memory resources in a type-erased way (hence the "polymorphic" in the name), like std::pmr::vector or std::pmr::list.

There's also an awesome CppCon talk by John Lakos in two parts which explains those allocation strategies:

290
1
291
1
292
1
293
1
294
1

TL;DR

At last the experiment is over, and CMake 3.28 has official support for C++ 20 named modules enabled without having to set the CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API variable.

295
1
296
1
297
1
submitted 2 years ago* (last edited 2 years ago) by ylai@lemmy.ml to c/cpp@programming.dev
298
1

I was trying to replicate an example of the last example of this section of this opengl tutorial, but without the textures, with wireframe cubes and with all the cubes rotating but when i run it only 1 cube is rendered.

I tried to do it again from scratch but only with c style code (except by the shaders and the glfw window) and i got the same result. Why it only renders 1 cube?

vertex shader: https://pastebin.com/6VzJKwBN fragment shader: https://pastebin.com/Ns9dLmqe the source file: https://pastebin.com/MvQtQG3g canned_glfw_window.hpp: https://pastebin.com/h2zD1WbK canned_glfw_window.cpp: https://pastebin.com/N2WX7NT8

299
1
300
1
view more: ‹ prev next ›

C++

2365 readers
1 users here now

The center for all discussion and news regarding C++.

Rules

founded 3 years ago
MODERATORS