MC++ slower than C#?

  • Thread starter Thread starter 011
  • Start date Start date
0

011

Hello, All!

I've realized some math algorithm in C# and MC++. The feature of it
is allocating a lot of memory. So the problem is that C# version
works much faster that MC++ version. And execution speed of MC++
app is slowly decreasing. Why could be so?

Regards, 011.

Winamp 5.0 (playing): Stratovarius - Holy Light (instrumental)
 
Hello!
You wrote on Thu, 18 Mar 2004 00:49:02 +0500:
I've realized some math algorithm in C# and MC++. The feature of
it is allocating a lot of memory. So the problem is that C#
version works much faster that MC++ version. And execution speed
of MC++ app is slowly decreasing. Why could be so?

Here's some code:

MC++

void MainClass::AddCombinations(ObjectSet*& pObjCombSet, ObjectSet*& pSuspObjSetSet)
{
Type* pType = (reinterpret_cast<ObjectSet*>(pSuspObjSetSet->List->Item[0]))->List->Item[0]->GetType();
uint cnt __gc[] = new uint __gc[pSuspObjSetSet->Count];
uint maxcnt __gc[] = new uint __gc[pSuspObjSetSet->Count];
bool bInit = true;
bool bEnd = false;
while(!bEnd)
{
ObjectCombination* pObjComb = new ObjectCombination(pType);
for(uint i = 0; i < (uint)pSuspObjSetSet->Count; i++)
{
ObjectSet* pObjSet = reinterpret_cast<ObjectSet*>(pSuspObjSetSet->List->Item);
Object* pObj = pObjSet->List->Item[cnt];
if(pObj->GetType() == Type::GetType(S"GS.ErrorSearchEngine.Transition"))


The GetType should be hoisted out of the loop. Even better you should
just use a dynamic cast. e.g.

if (Transition* pTr = dynamic_cast<Transition*>(pObj))
{
if(pTr->BaseNum != Transition::NullBaseTrNum)
pTr->SetNumToBase();
}

The reinterpret_cast may have been wrong - you aren't meant to
reinterpret_cast between managed pointer types.
pObjComb->List->Add(pObj);

if(bInit)
maxcnt = (uint)pObjSet->Count;
}

ShellSort(pObjComb->List);
bool bExist = false;
for(int i = 0; i < pObjCombSet->Count; i++)
{
ObjectCombination* oc = reinterpret_cast<ObjectCombination*>(pObjCombSet->List->Item);


That should be a __try_cast (or possibly a static_cast), not a
reinterpret_cast.

Tom
 
Back
Top