Comments (5)
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.
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.
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.
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.
See that one byte allocation at the end? This will do the trick.
from crossbridge.
Related Issues (20)
- Merge codebase to the official SWIG project HOT 3
- Cannot build master branch on Windows platform using Cygwin HOT 6
- Cannot build master branch on Mac platform using Travis-CI HOT 2
- getting started HOT 7
- Building the SDK HOT 1
- pthreads and workers support HOT 10
- getting started HOT 17
- performance aspects of crossbridge code HOT 2
- GDB. HOT 1
- fopen with directories makes fseek throw HOT 2
- PlayerKernel.open() throws exception when opening ISpecialFile file with O_TRUNC
- Cygwin dll files is missing HOT 1
- simple app used flashcc socket throws 'terminate called after throwing an instance of 'AS3::ui::var'' HOT 1
- Can't get it to work with SFML
- how do i link a static lib which build by cygwin HOT 1
- Use crossbridge to compile client.c to swc but failed because of a link error HOT 1
- gcc in cygwin is not support windows 10
- archive project? HOT 4
- crossbridge and C++11 HOT 10
- Disable output in adl
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crossbridge.