Re: How to know how many bytes in buffer?
"Boki" <bokiteam@ms21.hinet.net> wrote in message
news:1149479689.179066.271380@y43g2000cwc.googlegroups.com
Hi All,
In VB, we can use "MSComm1.InBufferCount" to get the count of uart
buffer.
Could you please advice how to do that in VC?
What sort of buffer is it? If it is a std::vector like
std::vector<int> vec;
you can use the capacity() member function and multiply it by sizeof(T),
where T is the type being stored (int in the example I gave).
If it is an array like
int buffer[] = {1,3,3,34,4};
you can use sizeof(buffer), but only in the scope in which the array is
declared. If the array name is passed to a function, then you cannot
retrieve the size from the array name within the function.
If the array is dynamically allocated
int *ptr = (int*)malloc(20);
then there is no standard way to retrieved the size of the buffer pointed
to. However, Microsoft offers an function that is an extension to the
Standard called _msize. This is only documented to work with malloc (and
calloc and realloc), but it also seems to work with new.
--
John Carson