memset

initialize two dimensional array of pointer elements using memset

Hi, I have a these structures definitions typedef struct my_s { int x; int y; } my_T; typedef struct your_s { my_T * x; } your_T; your_T array[MAX_COL][MAX_ROW]; To initialize the array's pointer to NULL, can I do: memset (array, 0, sizeof(array)) this does not look right to me,,, appreciate some advise. Thanks ...

how to set pointer to a memory to NULL using memset?

Hi, I have a structure typedef struct my_s { int x; ... } my_T; my_t * p_my_t; I want to set the address of p_my_t to NULL, tried: memset (&p_my_t, 0, sizeof(my_t*)) This does not look right, what is the correct way of doing this? appreciate it... Amendment to question - asking a radically more complex question: Thank...

memset and SIGSEGV

I have been facing a weird issue in a piece of code. void app_ErrDesc(char *ps_logbuf, char *pc_buf_err_recno) { char *pc_logbuf_in; char rec_num[10]; char *y = "|"; int i, j; memset(rec_num, 0, sizeof(rec_num)); memset(pc_buf_err_recno, 0, LOGBUFF); ..... ..... } For some reason the first me...

C memset seems to not write to every member

I wrote a small coordinate class to handle both int and float coordinates. template <class T> class vector2 { public: vector2() { memset(this, 0, sizeof(this)); } T x; T y; }; Then in main() I do: vector2<int> v; But according to my MSVC debugger, only the x value is set to 0, the y value is untouched. Ive never used si...

unistd.h read() is reading more data then being written

I'm reading/writing data off of a named pipe. On the writing side it says that it's writing a constant 110 bytes. On the Reading side for the majority of time it says that it's reading 110 bytes which is correct, but other times it says its reading 220 bytes or 330 bytes. Which is right in the fact that when I print it out it's printing ...

When zeroing a struct such as sockaddr_in, sockaddr_in6 and addrinfo before use, which is correct: memset, an initializer or either?

Whenever I look at real code or example socket code in books, man pages and websites, I almost always see something like: struct sockaddr_in foo; memset(&foo, 0, sizeof foo); /* or bzero(), which POSIX marks as LEGACY, and is not in standard C */ foo.sin_port = htons(42); instead of: struct sockaddr_in foo = { 0 }; /* if at least o...

C: Using memset function

This is the code that I want to try to write: #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <malloc.h> int main(int argc, char *argv[]) { float arry[3] = {0}; memset(arry, (int) 10.0, 3*sizeof(float)); return 0; } My problem is that I want to see if it's possible to use memset to ...

char array vs. char pointer

Hey, When receiving data through a socket using recv, I've noticed that, with: char buffer[4]; memset(buffer, 0, 4); recv(socket, buffer, 4, 0); I receive mesgx�� "mesg" being what I sent, with some random characters appended. If I use char * method = (char *) malloc(4); memset(buffer, 0, 4); recv(socket, buffer, 4, 0); ...

memset not filling array

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[0]); free(ecx); Very simply put, why is my output the following? 0D0D0D0D BAADF00D ps: u32 is a simple typedef of unsigned int edit: ...

Windows Magnification API, .NET and matrices.

I'm trying to create a magnifier app in .net using the Windows Magnification API. I've pretty much got everything working except for actually setting the magnification level (which defaults to 100%). The problem is, I can't find any examples anywhere on the net and all the documentation for the API is C++ code. This is the particular ...

What is the difference between memset and memcpy in C

I've read the function headers, but I'm still not sure what exactly the difference is in terms of use cases. Thanks! ...

Should C++ programmer avoid memset?

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 code above,if you do not use memset,how could you make a[1..1024] filled with zero?Whats wrong with memset in C++? thanks. ...

C++ equivalent for memset on char*

Hello I have this code char * oldname = new char[strlen(name) + 1]; memcpy(oldname,name,strlen(name) + 1); name = new char[strlen(oldname) + strlen(r.name) + 1]; memset(name, '\0', strlen(name)); strcat(name,oldname); strcat(name," "); strcat(name,r.name); I understand that it is a no no to use memcpy and memset but I...

Can I designate a Java-like 'constructor' in c?

I want to 'construct' (read: malloc and memset) my hashtable in c. To do this, I created a function as follows: int maketable(struct hash_entry **table, int size){ table = (struct hash_entry **)malloc(size*sizeof(struct hash_entry *)); int i = 0; for (; i<size; i++) { memset(table[i], '\0', sizeof(struct hash_entry...

Problem with memset after an instance of a user defined class is created and a file is opened

I'm having a weird problem with memset, that was something to do with a class I'm creating before it and a file I'm opening in the constructor. The class I'm working with normally reads in an array and transforms it into another array, but that's not important. The class I'm working with is: #include <vector> #include <algorithm> using ...

Exception in Memset

When try to do a memset it gives the following exception "Unhandled exception at 0x1023af7d (PxSmartInterface.dll) in SendOutDllTestExe.exe: 0xC0000005: Access violation writing location 0x40e3a80e." My memset statement will look like this memset(lpStatus, 0, csStatus.GetLength()); ...

Fastest way to zero out a 2d array in C?

I want to repeatedly zero a large 2d array in C. This is what I do at the moment: for(j = 0; j < n; j++) { for(i = 0; i < n; i++) { array[i][j] = 0; } } I've tried using memset: memset(array, 0, sizeof(array)) But this only works for 1D arrays. When I printf the contents of the 2D array, the first row is zeroe...

C++ Memory Allocation & Linked List Implementation

I'm writing software to simulate the "first-fit" memory allocation schema. Basically, I allocate a large X megabyte chunk of memory and subdivide it into blocks when chunks are requested according to the schema. I'm using a linked list called "node" as a header for each block of memory (so that we can find the next block without tediou...

MemSet & MemCopy

I'm writing a memory allocator, and I need a way to store an integer inside of a chunk of memory. This integer will represent the size of the block so I can navigate to the end given the pointer to the beginning. Here's my test example: // EDIT: Declared space for testInt int* testInt = new int; head_ptr = (char*) malloc(4*1024*1...

Problems Using memset and memcpy

So I am trying to create a Memory Management System. In order to do this I have a set amount of space (allocated by malloc) and then I have a function myMalloc which will essentially return a pointer to the space allocated. Since we will then try and free it, we are trying to set a header of the allocated space to be the size of the al...