This is a basic question. But, I think understanding this would be helpful to play with buffers in 'C'. Thanks.
Just a sample snippet
char *test_buff = (char *) malloc(512); //allocate 512 bytes in heap memory. bzero(test_buff, 512); //Reset buffer instead of Junk/garbage. /* random code here to fill-in the buffer called "test_buff"...*/ ... /* Send data to another host/system [this doesn't matter though] * using buffer "test_buff". */ sendto(sock_descriptor, test_buff /*buffer to send data*/, sizeof(*test_buff) ,...,...); // option-1 /* OR */ sendto(sock_descriptor, test_buff /*buffer to send data*/, 512 /* actual malloced size*/ ,...,...); // option-2
- Which one of the two is better [between option-1/option-2] way of using buffer? I hope option-1 makes sense, as it has length/size of valid data bytes of send buffer or "test_buff" in this case.
Thanks for your time and input.