Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: 31 Jan 2006 14:14:08 -0800,    group: microsoft.public.platformsdk.messaging        back       


Saving large attachments to memory   
Subject: Saving large attachments to memory

Please forgive the cross-posting.

My add-in saves several 200MB attachments to a memory buffer.

I notice that the calls to IStream::Read
can take wildly variable amounts of time,
for identically-sized attachments.

IStream::Read consistently takes over two minutes(!) to return for the
first two attachments,
but it returns in only a few seconds for the subsequent attachments!

It would make sense to me if only the first call to IStream::Read took
a very long time,
as the operating system may need to actually commit memory.
But, the delay is occurring for the first *and* second large
attachments (but none thereafter)!

Please find my code below.


Would anyone have any thoughts as to what might be causing the
performance difference?

Are there any properties of the attachments that could explain the
difference?

Is there a different way to copy the attachment data to memory?

Thanks very much for any help or recommendations!

Mike


static BOOL SaveAttachmentFromMemoryUsingExMAPI (IAttach* pAttach)
{
    /*
     * Try to get the contents of the attachment.
     */

    BYTE* pAttachmentBuffer = NULL;
    ULONG ulAttachmentSize = 0L;

    IStream* pStream = NULL;

    /*
     * Fetch an IStream interface to the attachment's
PR_ATTACH_DATA_BIN property.
     */
    if ((hr = pAttach->OpenProperty (PR_ATTACH_DATA_BIN, &IID_IStream,
STGM_READ, NULL, (LPUNKNOWN*) &pStream)) != S_OK)
    {
        Error();
    }

    if (pStream == NULL)
    {
        Error();
    }


    /*
     * Fetch the attachment's size.
     */
    STATSTG statstg;
    memset (&statstg, 0, sizeof(STATSTG));

    if ((hr = pStream->Stat (&statstg, STATFLAG_NONAME)) != S_OK)
    {
        Error();
    }

    // Bail if attachment size >= 4GB!

    ulAttachmentSize = statstg.cbSize.LowPart;


    /*
     * Get memory buffer to copy attachment into.
     * Note: GetBigMemoryBuffer uses C RTL realloc() to obtain a memory
buffer.
     */
    pAttachmentBuffer = GetBigMemoryBuffer (ulAttachmentSize);


    /*
     * Read attachment contents into buffer from stream.
     */
    ULONG ulBytesToRead = ulAttachmentSize;
    ULONG ulBytesRead = 0L;

    while (ulBytesToRead > 0)
    {
        if ((hr = pStream->Read (pAttachmentBuffer, ulBytesToRead,
&ulBytesRead)) != S_OK)
        {
            Error();
        }
        ulBytesToRead -= ulBytesRead;
    }

    if (pStream != NULL)
    {
        pStream->Release();
        pStream = NULL;
    }

    /*
     * Save memory buffer containing attachment data.
     */
    SaveMemoryBufferContainingAttachmentData();
}
date: 31 Jan 2006 14:14:08 -0800   author:   MikeJohnson

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us