Re: Question about buffer size given to erl_receive_msg in erl_connect
In C, a buffer is represented by a pointer. Pointers do not carry size information, and there is no means by which you know where the end-of-buffer is. Hence, it is C-idiomatic to supply another argument, bufsize, indicating the size of the buffer the pointer is pointing at.
If you give a too small bufsize, you are not going to use up the whole buffer. If you give a too large bufsize, you will overwrite data after the buffer in memory. This is wrong and usually leads to program crashes. Also, allocation checkers will detect this for you and warn you that your program is wrong.
If the message does not fit into the buffer, the call will fail and set and error indicating that the message is too large to fit inside the buffer. You could then try to extend the buffer and try again.
The xreceive call assumes the buffer is allocated by malloc. If it doesn't fit, the call will create a buffer large enough for the message and reallocate. This is why the types are different: you supply the addresses of the buffer pointer and the bufsize counter. Hence the call can update the contents of those addresses with the newly formed buffer, should it decide to move them.
The reason both calls exist is because it isn't always the case that the buffer will be allocated by malloc on the heap. You may statically allocate the buffer, or allocate it on the stack, for instance.