518 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
4
votes
5
answers
262
views
What is the alternative to declare a Variable-Length array in C, that may exceed Stack size, without the need of Dynamic Memory allocation?
I have the following code snippet in C that declares multiple one-dimensional and two-dimensional arrays of type double.
double func(double alphas[], double betas[], double rhos[], double **X, ...
0
votes
0
answers
31
views
How do fread and malloc affect RAM utilization in encryption process?
I am working on an application (Linux based) that uses AES-256 encryption and observed a significant increase in RAM usage during encryption. Initially, the process consumes about 3 MB of RAM (checked ...
1
vote
3
answers
141
views
Using memset() after malloc() causes assertion
I have a struct like this:
struct state {
bool isfinal;
bool *isfull;
char **board;
};
isfull is an array and board is a 2D array.
I can allocate memory for the arrays with this function:
...
-2
votes
2
answers
158
views
use memset for array of struct in C++
Well, I want a function like memset but for struct, so that it can be used on some or all elements, like this:
// create array of person data elements
struct {
unsigned char name[25];
unsigned ...
2
votes
1
answer
181
views
Efficient method to initialize a really large C++ vector with the same values
I was doing this leetcode problem and I had to initialize a very large 2D DP array of size 2^14 x 14 with all entries set to -1 to solve the problem. However I noticed a big performance difference ...
-2
votes
1
answer
519
views
memset() vs. std::fill() [duplicate]
Can anyone tell me the difference between memset() and std::fill() in c++?
I am quite confused why my code doesn't work with memset() but does with std::fill().
I am making a Sieve of Eratosthenes ...
3
votes
1
answer
192
views
Why did GCC turn a for loop to clear an array into a memset?
For a project to learn C, I decided for fun to put the code in Compiler Explorer and compare the assembly output with the C code. Here's a minimal example of some code
unsigned char count[256][256];
...
0
votes
0
answers
90
views
ZynqMP memset() raises unhandled alignment fault error
I'm having trouble using memset() in C; let me explain.
I'm working with embedded Linux on a zynq ultrascale+ board running Linux kernel v4.14. I'm performing some DMA transfers from the logic side of ...
0
votes
0
answers
339
views
ARM64. Calling memset() on the address returned by mmap() PCIe BAR causes a BUS error
I wrote a very simple test program in the application layer. First, I open the PCIe device, then mmap() the starting space of the PCIe BAR. Finally, I use the address returned by mmap(), apply an ...
0
votes
1
answer
145
views
memset bus error after mmap when init shared memory
The scenario is one process writes the program metric stats data to shared memory file.And another process will read the file and send the data to metric server.
The bus error and core dump occurs in ...
-1
votes
2
answers
127
views
Why does memset not store all values similarly in 2D array?
I have a 2D array set as
long long arr[500][500]
Running this main function, I get different values for m=-1 and m=-3:
int main(){
memset(arr,m,sizeof(arr));
for(int i=0;i<10;i++)
...
1
vote
2
answers
214
views
How correctly memset array of bool
I have bool array and I want initialize all elements to false. What is the correct way using memset. I see these examples on stackoverflow:
bool arr[10];
memset(arr,0,sizeof(arr));
and
bool arr[10];
...
5
votes
1
answer
233
views
Is it legal to zero empty C++ classes in the constructor and inherit from them?
It is not very rare to find a library that zeros its objects in the constructors using memset. And sometimes it happens to empty classes as well. Is it safe, especially when one inherits such classes?
...
2
votes
1
answer
732
views
Efficient way to reset array of structs which contain a std::atomic member?
Let's say I have a struct Foo s. t.
struct alignas(64) Foo {
std::atomic<int> value;
Foo* other;
};
Then, if I have an array Foo array[2048]; of Foo's: I already have initialized the ...
1
vote
0
answers
186
views
Memset warning treated as error, based on its thrd argument [duplicate]
When built without AM_CXXFLAGS += -Wno-memset-elt-size on the AutoMake Makefile, i get this error:
error: ‘memset’ used with length equal to number of elements without multiplication by element size [-...