[prev in list] [next in list] [prev in thread] [next in thread]
List: ms-atl
Subject: STL
From: "Perley P. Laliberte" <Perley-Laliberte () FORUM-FINANCIAL ! COM>
Date: 2001-07-13 17:41:52
[Download RAW message or body]
Hello,
This may be ot but I thought I may find some encouraging words from
someone, so here goes. I trying to implement a STL map that will at some
point be converted into a safearray. I have it working but the performance
is pretty slow.(I have posted several question along these lines which have
helped me narrow down my options.)
I am wondering is there some canned algorithm for doing this - this being
convert a map into a byte stream and then into a safearray?
Is there and alternative to using memcpy and how expensive is using memcpy
several time as I'm using it in the included code?
I included this code so I could hopefully get some feedback on mistakes I'm
making/not making and possible suggestions on how to improvement the
performance problem I'm confronting.
definition of STL map:
#include <map>
#include "ISSHelper.h"
using namespace std;
class x : public y
{
typedef map<CComBSTR, CComVariant> m_MM;
typedef m_MM::value_type m_vtM;
m_MM m_tmMap;
*** (as an aside)
*** what do I need to add to get rid of the using namespace std?
So with this map is there a predefined algorithm that will copy the data
into a raw byte stream, array, buffer...?
I have it working presently like so any idea on better approaches are
welcomed:
HRESULT hr = S_OK;
CISSHelper ISSHelper;
// Store number of property name/value pairs to the stream.
int nCount = m_tmMap.size();
//***the write methods implementation is included at the end
ISSHelper.Write(&nCount, sizeof(int), NULL);
// Iterate and stream each property name/value pair to the stream.
while (it != m_tmMap.end())
{
CComBSTR bstrName = bstrKey = it->first;
CComVariant varVal = vtVal = it->second;
hr = bstrName.WriteToStream((IStream*)&ISSHelper);
if (FAILED(hr))
{
return hr;
}
hr = varVal.WriteToStream((IStream*)&ISSHelper);
if (FAILED(hr))
{
return hr;
}
}
//Database class has a set, get and delete
PersistentData oPD;
// Creating a safearray of variants with three elements.
VARIANT varData;
SAFEARRAY FAR* psa;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = ISSHelper.m_ulLength;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
// Try to lock and access safe array's raw memory pointer.
LPBYTE lpBuffer;
hr = SafeArrayAccessData(psa,(void **)&lpBuffer);
if (FAILED(hr))
{
::SafeArrayDestroy(psa);
return hr;
}
// Copy bytes from global heap to safe array.
ISSHelper.Read(lpBuffer, ISSHelper.m_ulLength, NULL);
hr = SafeArrayUnaccessData(psa);
if (FAILED(hr))
return hr;
// Set variant to new safe array.
varData.vt = VT_ARRAY | VT_UI1;
varData.parray = psa;
oPD.setSession(m_bstrConnectString, m_bstrGUID, varData);
return hr;
this is the definition of the ISSHelper.Write that that I'm using(was in a
microsoft example of handling BLOB's or something).
HRESULT CISSHelper::Write( const void *pv, ULONG cb, ULONG* pcbWritten )
{
// Check parameters.
if ( !pv ) return STG_E_INVALIDPOINTER;
if ( pcbWritten ) *pcbWritten = 0;
if ( 0 == cb ) return S_OK;
// Enlarge the current buffer.
m_ulLength += cb;
// Grow internal buffer to new size.
while ( m_ulLength > m_ulBufSize )
{
m_ulBufSize += BLOCK;
if ( m_ulLength < m_ulBufSize )
{
m_pBuffer = CoTaskMemRealloc( m_pBuffer,
m_ulBufSize );
}
}
// Check for out of memory situation.
if ( NULL == m_pBuffer )
{
Clear();
return E_OUTOFMEMORY;
}
// Copy callers memory to internal bufffer and update write
position.
memcpy( (void*)((BYTE*)m_pBuffer + m_iWritePos), pv, cb );
m_iWritePos += cb;
// Return bytes written to caller.
if ( pcbWritten ) *pcbWritten = cb;
return S_OK;
}
Any ideas, thoughts or suggestions welcomed.
Thanks,
Perl
----------------------------------------------------------------
Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:ATL-signoff-request@DISCUSS.MICROSOFT.COM
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic