473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

COM and C++ perf problems

Hi,

background:
----------

I am the maintainer of a COM C++ dll that is used to read
binary data from a specific file format. I was recently
tasked to speed up the execution speed of this dll. In
analysis I saw that you would very often get fseek()'s
followed by either fwrite()'s or fread()'s. So my
optimisation strategy was to improve file IO by using memory
mapped file IO (using Win32).

The basic access paradigm to these files, in this
implementation, is this:

VARIANT GetData( long recordNumber, long fieldNumber );
void SetData( long recordNumber, long fieldNumber, VARIANT
data );

In other words, the file is basically a binary table storage
mechanism.

I defined the following pure virtual "interface" class that
would be the IO mechanism that the dll would use to have raw
access to the file's bytes. The idea is that I have one
implementation wrapping the stdlib's fopen(), fseek(),
fwrite/read() etc. And another class that would wrap the
memory mapped file io mechanism.

class StorageProvider
{
public:
StorageProvider();
virtual ~StorageProvider();

virtual SIZE_T FileSize() = 0;

virtual ErrorObject CreateFile( std::string FileName ) = 0;
virtual ErrorObject OpenFile( std::string FileName, bool ReadOnly ) =
0;
virtual ErrorObject CloseFile() = 0;

// if Position == -1, it means that the internal
// pointer must be used as the position.
// the internal pointer must make this behave like fread, fwrite and
fseek does
virtual ErrorObject WriteData( const void* Source, SIZE_T Length, long
Position = -1 ) = 0;
virtual ErrorObject ReadData( void* Destination, SIZE_T Length, long
Position = -1 ) = 0;
virtual ErrorObject ChangeSize( SIZE_T Size ) = 0;

virtual bool IsOpen() = 0;

protected:
ErrorObject& mError;

};

As you might see, it is meant to be used as a drop-in
replacement for the stdlib file access calls.

In the dll you have the following 2 lines that determines
whether it will use the stdlib wrapper or the memory mapped
file io wrapper:

//StorageProvider *m_storage = new FileStreamStorage();
StorageProvider *m_storage = new MemoryMappedFile();

Aside from these 2 lines, in the following problem I have
not changed one single other line at all.

I am pretty sure that the individual implementations are
correct. I used another program during development and
testing with which I wrote and read to random positions
within big files. I saw the appropriate improvement in speed
when using the memory mapped file io wrapper over the stdlib
wrapper. In the test below I also get the same data back in
both implementations.

problem:
-------
I have a VB6 appy that calls the COM dll
methods to do some test reading from a file that conforms to
the file format.

If I use the stdlib wrapper (FileStreamStorage) the
application takes a total of ~0.02 seconds on average
(determined using the GetTickCount() call in kernel32.dll).

If I use the memory mapped file io wrapper
(MemoryMappedFile) then THE SAME CODE takes ~0.8 seconds, on
average.

I have a copy of CompuWare devPartner here that says, when I
am using the memory mapped file wrapper implementation, the
time is split between code I have source for (14%) and
system (86%). In the system list the main taker-of-time is a
call to rpcrt4.dll; IclsDMBinaryFile::FieldValue_Get.

What is interesting about this is that in my dll I have
class called clsDMBinaryFile with a method
get_FieldValue(VARIANT index, VARIANT *pVal) that is
exported to COM in the IDL.

I am not clued up enough to even do further analysis. I have
very little experiance in COM so any help or pointers will
be GREATLY appreciated.

Friendly Regards,
Pieter Breed

Jul 22 '05 #1
0 1155

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric S. Johansson | last post by:
I've seen a couple solutions for making CGI faster without significant rewrite. The only one I've been able to locate is fastCGI. I seem to recall something like speed CGI or speedy CGI but I...
14
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
15
by: Raj | last post by:
Hello all: We have a table with about 2400 cells. Our requirement is to highlight the cells in the table whose data has changed, every 5 seconds. Our script behaves relatively ok in Firefox, but...
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
3
by: Joshua Coady | last post by:
Do Trace calls have any impact on performance if Trace is disabled in the config file? Josh
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
2
by: Stefan Kuhr | last post by:
Hello everyone, I hope this is not an FAQ and that somebody can answer this: As part of our webservice installation we run aspnet_regiis.exe -ir -enable on computers where the web...
1
by: Ben | last post by:
Hi, I registered some custom perf counters that i want to use in my app (all of type NumberOfItems32). I added them under the same category name but different counter names... Same code work...
1
by: Ben | last post by:
hi, i have this line in a web app to create a custom perf category: PerformanceCounterCategory.Create(categoryName, categoryDesc, PerformanceCounterCategoryType.SingleInstance, ccdc); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.