1

I have an array of pixels of 1049088 size, in my computer, and I want to fill it completely. But when I use memset it just gets filled to a point of the array, not the whole block.

I have gone to http://www.cplusplus.com/reference/cstring/memset/ and it says nothing about a maximum size. Also, my variable is size_t (unsigned int) so it should return me an error if I put a higher value than expected, but it's in range.

memset((void*)pixels, BLACK_CLR, w_widthxheight);

The w_widthxheight is a size_t that contains 1049088. The pixels is a COLORREF array with the size of the same variable (w_widthxheight). The BLACK_CLR constant contains 0.

If there's any alternative to memset, because I've read that it's unefficient somewhere (but works fine the first x values of the array) it would be good too.

1 Answer 1

4

You are giving the size in elements, but memset expects the size to be in bytes. So this should fix it:

memset((void*)pixels, BLACK_CLR, w_widthxheight * sizeof( COLORREF ) );
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.