Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
0 votes
1 answer
23 views

Alignment problem with UBO on CPU/GPU, GLSL/VULKAN

After adding directional lights to UBO, the light is incorrect on scene. Tried to shuffle elements around, but it doesn't help. If i correct, GLSL UBO structure should be 920 bytes in size? What is ...
Ciborg's user avatar
  • 25
0 votes
0 answers
24 views

getting aligned pointer inside storage to place object

I have a storage in a form of an array of bytes. On the stack // storage on the stack, no requirement on alignment unsigned char storage[N]; Or on the heap // storage on the heap, no requirement on ...
Oersted's user avatar
  • 1,706
0 votes
0 answers
39 views

what can be overaligned types

is "Tis overaligned" equivalent to alignof(T)>alignof(std::max_align_t)? And is it possible to have an overaligned type without using alignas keyword or another explicit alignment ...
Oersted's user avatar
  • 1,706
0 votes
0 answers
31 views

Getting heap storage with proper alignment in C++ for overaligned type

In some use case, you'll need to allocate storage before creating objects inside this storage. Then in order to create these objects, you may need to use placement new: T *pobj = new(pstorage); yet ...
Oersted's user avatar
  • 1,706
-2 votes
1 answer
64 views

Getting heap storage with proper alignment in C++ for non-overaligned type

In some use case, you'll need to allocate storage before creating objects inside this storage. Then in order to create these objects, you may need to use placement new: T *pobj = new(pstorage); yet ...
Oersted's user avatar
  • 1,706
2 votes
1 answer
83 views

Correctly deleting a dynamically allocated plain array, allocated with `std::align_val_t` alignment parameter

As an answer to Idiom for initializing an std::array using a generator function taking the index?, I proposed a way to obtain a properly aligned storage. Yet I think that my solution can be simplified,...
Oersted's user avatar
  • 1,706
1 vote
1 answer
75 views

How to know the size of an aligned type including padding

I have a buffer with chunks that align to the cacheline size, but have arbitrary length, let's say 100 bytes. It is clear to me that the buffer (vector) elements are aligned on cacheline borders, but ...
glades's user avatar
  • 4,475
1 vote
1 answer
38 views

C++ rebind allocator with two template parameter

I'm writing an allocator that takes alignment as a template parameter also the alignment: template<typename T, std::align_val_t alignment> class AlignedAllocator { public: using value_type = T;...
MaPo's user avatar
  • 683
1 vote
2 answers
106 views

Why is the size of this subclass the same as the base class even though it adds a member variable?

In the following code, why is the size of Parent the same as the size of Child (even though Child adds a member variable)? Another weird behaviour: if I comment out the line where b is defined, the ...
Mathias L.'s user avatar
1 vote
0 answers
68 views

Using placement new on underaligned buffer in C++

Given a buffer char buf[sizeof(T) + alignof(T) - 1]; Is calling placement new that constructs an instance of T on the pointer to the first element of buf that is located at an address which is a ...
CyanideGourmet's user avatar
1 vote
1 answer
50 views

Converting a templated data into another templated data

I have a method returning a templated class and taking as argument another templated class such as : template <class T, class U> T caster(U* u) { return reinterpret_cast<T>(u); } ...
LPo's user avatar
  • 87
7 votes
3 answers
442 views

How to control the size of a class to be a multiple of the size of a member?

I have the following class, struct employee { std::string name; short salary; std::size_t age; }; Just as an example, in Linux amd64, the size of the struct is 48 bytes, and the size of ...
alfC's user avatar
  • 15.6k
2 votes
1 answer
116 views

C++: Is there ever a reason to make alignof > sizeof for a type

As indicated in this question, it is possible to have alignment greater than size for a type, you just can't make an array of it. However you can make an array of char[alignof(T)] and reinterpret_cast ...
metamorphosis's user avatar
0 votes
0 answers
66 views

why did the align addresses have gaps (c++)?

#include <iostream> using namespace std; int main() { alignas(0x10000) int ptr[42]; cout << ptr << endl; if (auto ptr = aligned_alloc(0x1000, 42 * sizeof(int))) { cout &...
jackwang's user avatar
0 votes
1 answer
148 views

Why memory alignment of structs that contain arrays of type T is always 1

I was exploring memory alignment and padding, and thought that I got the hang of it until I came across this: struct Example { int x1; // 4 char c; // 1 + 3 padding int x2; // 4 }; ...
Zaki's user avatar
  • 107

15 30 50 per page
1
2 3 4 5
23