Giter Site home page Giter Site logo

Comments (5)

cbakgly avatar cbakgly commented on July 21, 2024

Surely you can.
The code you see just want to make sure a big memory is available.
Image that domain memory is where your c++ code data lives in, just like the OS mem you have for stack and heap.

On Jan 5, 2014, at 12:39 AM, trungnq97 [email protected] wrote:

Hi,

In side a loop, I use malloc to allocate some domain memory, and free it at the end of a loop. It works well for a while, then I received lots of RangeError.

RangeError: Error #1506: The specified range is invalid.

var pcmPtr:int = CModule.malloc(FRAME_SIZE_BYTE * CHANNEL);

I've seen this https://github.com/adobe-flash/crossbridge/wiki/Memory-Fragmentation, but I don't understand why malloc and free at the same time in init function.

protected function init(e:Event):void
{
var p:int=CModule.malloc(1024_1024_256);//pre-allocate a block domain memory, the size should be according to your project
if (!p)
throw(new Error("You have opened too many pages, close some of them or restart your browser!"));
CModule.malloc(1);//take up the domain memory
CModule.free(p);//release the pre-allocated memory so that it can be used for new C/C++ Object
...
}

Can preallocated memory fix RangeError issue?

Many thanks,
Trung


Reply to this email directly or view it on GitHub.

from crossbridge.

trungnq97 avatar trungnq97 commented on July 21, 2024

This init function can guarantee that there is enough memory at the time it runs, but it cannot guarantee when this function exits. Is it correct?

Can I put the pre-allocated memory code here (inside event ADDED_TO_STAGE)?

addEventListener(Event.ADDED_TO_STAGE, init);

and free it here (inside event REMOVED_FROM_STAGE)?

addEventListener(Event.REMOVED_FROM_STAGE, cleanup);

Many thanks,
Trung

from crossbridge.

cbakgly avatar cbakgly commented on July 21, 2024

Don't understand what you are trying to say.
You just call init() once to make sure you have a big memory area available for later allocation.

from crossbridge.

trungnq97 avatar trungnq97 commented on July 21, 2024

I thought that when this CModule.free(p); gets executed, the memory is free for other flash instance to take. So after that, there will be no guarantee that we can malloc the same amount of memory as in this example CModule.malloc(1024*1024*256); again. I am not 100% sure that it is correct or not.

If I CModule.malloc an amount of memory to preserve and I don't CModule.free it later, will this amount of memory be automatically released when user closes the page that contains my swf file?

from crossbridge.

cbakgly avatar cbakgly commented on July 21, 2024

See that one byte allocation at the end? This will do the trick.

from crossbridge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.