Jump to content

  • Log In with Google      Sign In   
  • Create Account

loboWu

Member Since 08 Mar 2006
Offline Last Active May 22 2014 12:01 AM

Topics I've Started

string array error

11 April 2014 - 03:34 AM

Dear andreas:

 

  I decare a string array

  ex:

        string[]   arr = { "11111" , "222222"};

 

   But If I remove the comma 

       

        string[]   arr = { "11111"   "222222"};
 
    angelscript won't report parsing error.
    Instead, this statement is equal to string[] arr={"11111222222"}; 
 
    Is it a bug?

uint token parse error!

13 February 2014 - 02:04 AM

Dear Andreas:

   please try this in 2.28.1

   void main()

   {

        uint8  uint8Temp;

        uint32 uint32B;

   }

 

   The variable name starting with (uint8, int8...) will result in parsing error.


array with object reference

10 February 2014 - 12:13 AM

Dear Andreas:
I found there's something strange about array constructor in 2.18.1.
 
I had a string class which is registered with reference.
The codes are similar with http://www.gamedev.net/topic/639252-asobj-ref-and-asobj-value-at-the-same-time/
 
and here is my testing code without fail
 

import void SetCurrentModel(string) from "model2";

void test(uint idx)

{
<span  style="color:#ff0000">string@[]</span> models={"111", "222", "333", "444", "555", "666", "666"};

if (idx <=6) SetCurrentModel(models[idx]);

else

SetCurrentModel("");

}


 
If I change the string array codes like this

 
import void SetCurrentModel(string) from "model2";

void test(uint idx)

{
<span  style="color:#ff0000">string[]</span> models={"111", "222", "333", "444", "555", "666", "666"};   //replace "string@ " with "string"

if (idx <=6) SetCurrentModel(models[idx]);

else

SetCurrentModel("");

}

There are some string memory leak in 2.18.1. (but that's fine in 2.17.0)

I couldn't point out the bug exactly, but I think there are 2 bugs with object reference array

1.  value assignment operators on reference types

2.  CScriptArray::Construct()


Terrible performance deficiency on asCRestore

06 August 2012 - 04:08 AM

Hi:
I am using 2.21.0 for a long while.
When I start to upgrade to 2.24.0a or the latest svn,
I found a performance issue.

Lets see the code.

[source lang="cpp"]In 2.21.0asCScriptFunction *asCRestore::ReadFunction(bool addToModule, bool addToEngine) {........... if( func->funcType == asFUNC_SCRIPT ) { engine->gc.AddScriptObjectToGC(func, &amp;engine->functionBehaviours); count = ReadEncodedUInt(); func->byteCode.Allocate(count, 0); ReadByteCode(func->byteCode.AddressOf(), count); ............... }}It allocate just one time for the function bytecode.[/source]

But In 2.24.0a~
[source lang="cpp"]void asCReader::ReadByteCode(asCScriptFunction *func){ // Read number of instructions asUINT numInstructions = ReadEncodedUInt(); // Reserve some space for the instructions func->byteCode.Allocate(numInstructions, 0); asUINT pos = 0; while( numInstructions ) //in my env, this could be 400K or more { asBYTE b; ReadData(&amp;b, 1); // Allocate the space for the instruction asUINT len = asBCTypeSize[asBCInfo[b].type]; func->byteCode.SetLength(func->byteCode.GetLength() + len); //too much allocate and memory copy here asDWORD *bc = func->byteCode.AddressOf() + pos; pos += len;.................................}[/source]

In my enviroment, I use angelscript to implement a huge database processor.
So in the most time, there are huge arrays.

For example, there is a array initial function which produce 400K bytecode instructions.
It take a long long time to restore bytecode.
Whould you help me to solve this problem?
Thanks,

Lobo Wu

array cross over modules

03 July 2011 - 02:12 AM

Dear WitchLord:
In the standard usage, the array object couldn't corss over modules.
I made some unsafe modification, to support that.

org code in add_on\scriptarray
CScriptArray &CScriptArray::operator=(const CScriptArray &other)
{
// Only perform the copy if the array types are the same
if( &other != this && 
  other.GetArrayObjectType() == GetArrayObjectType() )  
{
  if( buffer )
  {
   DeleteBuffer(buffer);
   buffer = 0;
  }

  // Copy all elements from the other array
  CreateBuffer(&buffer, other.buffer->numElements);
  CopyBuffer(buffer, other.buffer);
}

return *this;
}

But the ObjectType will be different if I precompile 2 modules separately.
So I do some modification
CScriptArray &CScriptArray::operator=(const CScriptArray &other)
{
// Only perform the copy if the array types are the same
if( &other != this )   //lobo fix
{
  bool bCopy = false;
  if (other.GetArrayObjectType() == GetArrayObjectType() )
   bCopy = true;
  else
  {
   int objID = GetArrayObjectType()->GetSubTypeId();
   int othID = other.GetArrayObjectType()->GetSubTypeId();
   if (objID & othID & asTYPEID_SCRIPTOBJECT) //If it is scriptojbect
   {
    asIObjectType *subtype = GetArrayObjectType()->GetEngine()->GetObjectTypeById(objID);
    asIObjectType *othtype = other.GetArrayObjectType()->GetEngine()->GetObjectTypeById(othID);
    if (strcmp(subtype->GetName(), othtype->GetName())==0)  // if the typename is the same, It is safe to do array copy ?  not always, but it is suitable for me
     bCopy = true;
   }
  }
  if (bCopy)
  {
   if( buffer )
   {
    DeleteBuffer(buffer);
    buffer = 0;
   }

   // Copy all elements from the other array
   CreateBuffer(&buffer, other.buffer->numElements);
   CopyBuffer(buffer, other.buffer);
  }
}

return *this;
}

The similar modification could be used in add_on\scriptdictionary.cpp
"bool CScriptDictionary::Get(const string &key, void *value, int typeId) const"

Thanks.

PARTNERS