36,433 questions
Best practices
0
votes
2
replies
22
views
Is it problematic to not check for memory allocation failure in C++?
I've written a decent amount of C, and every resource I read (books, web documentation, tutorials) insisted that I should never assume malloc() will always succeed.
But I've been learning C++ recently,...
Score of 0
0 answers
39 views
How to calculate wavefronts when broadcasting
If multiple threads among the 32 threads access the same bank at the same address (meaning when there’s broadcasting) while coexisting with LDS.64 or LDS.128, how to calculate wavefronts . Below is ...
Advice
2
votes
1
replies
78
views
Why did GCC drop the progbits flag in .section directives for objects in .data, .rodata?
Consider the following C/C++ compilation unit
extern int i;
int i = 1;
extern const int c;
const int c = 1;
And compiled with:
$ gcc -xc++ x.c -S -fdata-sections -static -o - | grep '\(data\|GCC\)'
...
Advice
1
vote
9
replies
262
views
Efficient memory usage in c programming
If we have dynamic memory allocation, which is best for using the memory efficiently, then why do we use static memory allocation every time? Can't we use dynamic memory everywhere??
Advice
0
votes
8
replies
229
views
Usage of pointers
As a beginner I don't understand why pointers are being used everywhere . When I got to know about pointers, I had lots of questions: Why can't we simply use another variable to store the value of ...
Advice
0
votes
0
replies
263
views
Cross-Platform Desktop Wars: Electron vs Tauri: How do you explain the tradeoffs to users (without sounding defensive)?
I am writing cause I wanted to get some opinions from folks here that have actually built and shipped with Electron.
Background: Building an API IDE on Electron. Not really “just an API client”, and ...
Advice
0
votes
10
replies
194
views
How does malloc() assign the value to the allocated memory?
I am trying to learn malloc() in C. My question is regarding how the values are stored once I malloc the memory.
To understand this, I wrote the following program:
size_t n_bytes = 4;
char *mmry_ptr = ...
Score of 2
0 answers
131 views
Visualizing memory as binary in natvis [closed]
I have a C++ hash map class that I'm writing natvis code for in order to easily inspect its members while debugging. One member of the class is char* myControlBytes which is an array of chars/bytes ...
Score of 0
1 answer
134 views
Corrupt object variables in C++ for ESP32 [duplicate]
I am creating a project for an ESP32. I'm quite new to ESP and C++ coding. I use PlatformIO inside VSCode.
It's a robot that will be driving around. It has Ultrasonic sensors to detect any obstacles. ...
Advice
0
votes
7
replies
138
views
Number of bits used for representing different types vs what the CPU uses
I was thinking about floats and doubles and was wondering if the fact that they use 32 bits and 64 bits respectively means there is a performance increase either in terms of memory used or time for ...
Best practices
0
votes
1
replies
121
views
How to reduce GPU memory usage when fine-tuning a large transformer model?
“I’m fine-tuning a transformer with batch size 8 and getting CUDA out-of-memory errors. Would gradient checkpointing or mixed precision help?”
Best practices
0
votes
12
replies
196
views
Using a C++ union for uninitialized memory
I am needing to manage memory for object allocation manually. I have been using a alignas(T) char storage[] array with dynamic casts. But what I really want is an array of uninitialized values.
Can I ...
Score of 4
1 answer
203 views
Memory leak happening with Python when creating numpy diagonal array and doing matrix math
P = y.T @ (np.diag(Wc) @ y) This line is creating increased memory usage for me in the below code on my Windows 11 machine. As soon as I run the code, I see the RAM usage increasing and skyrocketing. ...
Score of 4
1 answer
174 views
Reducing memory usage when writing chunks in order with Go parallel workers
I have a Go function for encrypting data in parallel using AES-GCM:
func encryptParallel(ctx context.Context, aead cipher.AEAD, w io.Writer, r io.Reader, workers uint64) error
The design is:
One ...
Score of -1
1 answer
336 views
What is the size of a std::function?
What is the size of a std::function? If the size is dependent on something, is there a theoretical maximum?
The size of closure (lambda function) not same as std::function or pointer explores the ...