LocalAlloc and LocalRealloc usage
Posted
by PaulH
on Stack Overflow
See other posts from Stack Overflow
or by PaulH
Published on 2010-05-06T20:31:50Z
Indexed on
2010/05/06
20:38 UTC
Read the original article
Hit count: 470
I have a Visual Studio 2008 C++ Windows Mobile 6 application where I'm using a FindFirst() / FindNext() style API to get a collection of items. I do not know how many items will be in the list ahead of time. So, I would like to dynamically allocate an array for these items.
Normally, I would use a std::vector<>, but, for other reasons, that's not an option for this application. So, I'm using LocalAlloc() and LocalReAlloc().
What I'm not clear on is if this memory should be marked fixed or moveable. The application runs fine either way. I'm just wondering what's 'correct'.
int count = 0;
INFO_STRUCT* info = ( INFO_STRUCT* )LocalAlloc( LHND, sizeof( INFO_STRUCT ) );
while( S_OK == GetInfo( &info[ count ] )
{
++count;
info = ( INFO_STRUCT* )LocalRealloc( info, sizeof( INFO_STRUCT ) * ( count + 1 ), LHND );
}
if( count > 0 )
{
// use the data in some interesting way...
}
LocalFree( info );
Thanks, PaulH
© Stack Overflow or respective owner