memset Questions
1
Solved
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 class...
Vivyan asked 25/3, 2024 at 18:21
11
Solved
I heard a saying that c++ programmers should avoid memset,
class ArrInit {
//! int a[1024] = { 0 };
int a[1024];
public:
ArrInit() { memset(a, 0, 1024 * sizeof(int)); }
};
so considering the ...
Sidwohl asked 29/12, 2009 at 17:52
1
Solved
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 array...
Unalterable asked 24/11, 2023 at 12:14
4
Solved
Well, the thing is simple, im getting
warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘struct FormatHashBuffers(CBlock*, char*, char*, char*)::<unnamed>’; u...
3
I'm trying to create my own versions of C functions and when I got to memcpy and memset I assumed that I should cast the destination and sources pointers to char *. However, I've seen many ex...
17
I need to fill a byte[] with a single non-zero value. How can I do this in C# without looping through each byte in the array?
Update: The comments seem to have split this into two questions -
Is...
Corrade asked 13/12, 2009 at 19:59
8
Solved
I need to write a repeating pattern to memory (e.g. 0x11223344), so that the whole memory looks like (in hex):
1122334411223344112233441122334411223344112233441122334411223344...
I can't figure ou...
Pricefixing asked 27/7, 2010 at 15:10
6
I want to know how I can use the memset() function in a two dimensional array in C.
I don't want to face any garbage problems in that array. How do I initialize this array?
Could someone explain...
13
Solved
I want to repeatedly zero a large 2d array in C. This is what I do at the moment:
// Array of size n * m, where n may not equal m
for(j = 0; j < n; j++)
{
for(i = 0; i < m; i++)
{
array[...
Dependent asked 25/3, 2010 at 13:57
4
Solved
I'm trying to build an application as tiny as possible, and in doing so I'm trying to avoid use of the CRT by using Win API calls instead of standard C/C++ calls. Unfortunately, I'm still getting a...
Brotherly asked 27/1, 2014 at 3:26
4
Solved
From looking at the CUDA 5.5 API Reference and the CUDA C Programming Guide it seems that there is no cudaCalloc(), an on-GPU equivalent of the standard C library's calloc().
Is there really no A...
3
Solved
From this comment in GCC bug #53119:
In C, {0} is the universal zero initializer equivalent to C++'s {} (the latter being invalid in C). It is necessary to use whenever you want a zero-initi...
Hydrous asked 30/11, 2021 at 13:20
2
Solved
Suppose there's a struct whose constructor does not initialize all member variables:
struct Foo {
int x;
Foo() {}
}
If I memset some buffer to 0, use placement new on that buffer to create an in...
Shoveler asked 9/8, 2021 at 14:13
7
Solved
I'm involved in one of those challenges where you try to produce the smallest possible binary, so I'm building my program without the C or C++ run-time libraries (RTL). I don't link to the DLL vers...
Chimkent asked 30/5, 2010 at 14:16
1
Solved
I am trying to write some bare metal code with a memset-style loop in it:
for (int i = 0; i < N; ++i) {
arr[i] = 0;
}
It is compiled with GCC and GCC is smart enough to turn that into a call t...
7
Solved
Is memset() more efficient than for loop.
Considering this code:
char x[500];
memset(x,0,sizeof(x));
And this one:
char x[500];
for(int i = 0 ; i < 500 ; i ++) x[i] = 0;
Which one is more effi...
Sudarium asked 9/9, 2011 at 21:32
0
Basically I am trying to understand why both gcc/clang use xmm register for their __builtin_memset even when the memory destination and size are both divisible by sizeof ymm (or zmm for that matter...
Greenery asked 1/1, 2021 at 23:32
10
Solved
char str[] = "beautiful earth";
memset(str, '*', 6);
printf("%s", str);
Output:
******ful earth
Like the above use of memset, can we initialize only a few integer array index values to 1 as give...
1
Solved
2
Solved
Quite by chance stumbled upon some code in kernel jungles and was a bit confused. There are two implementations of kzalloc(): in tools/virtio/linux/kernel.h and the main one in linux/slab.h. Obviou...
Maroon asked 17/1, 2020 at 11:55
9
Solved
In a Systems Programming class I took this previous semester, we had to implement a basic client/server in C. When initializing the structs, like sock_addr_in, or char buffers (that we used to send...
Keyboard asked 13/6, 2013 at 21:0
4
Solved
I am from Python background and recently learning C++. I was learning a C/C++ function called memset and following the online example from website https://www.geeksforgeeks.org/memset-in-cpp/...
Liriodendron asked 5/6, 2019 at 15:13
4
Solved
u32 iterations = 5;
u32* ecx = (u32*)malloc(sizeof(u32) * iterations);
memset(ecx, 0xBAADF00D, sizeof(u32) * iterations);
printf("%.8X\n", ecx[0]);
ecx[0] = 0xBAADF00D;
printf("%.8X\n", ecx...
3
Solved
I've researched code of some library and noticed that calls to calloc there are followed by memset for block allocated by calloc.
I've found this question with quite comprehensive answer on differe...
2
Solved
The manpage says about memset:
#include <string.h>
void *memset(void *s, int c, size_t n)
The memset() function fills the first n bytes of the memory area pointed to by s with the cons...
Wolfson asked 13/6, 2014 at 14:27
1 Next >
© 2022 - 2025 — McMap. All rights reserved.