Can't use memory allocated in C to write then read BitmapData in AS

Hi all,
I've been attempting to use Alchemy to allocate a chunk of memory in C, and then write a bitmap to the memory (via getPixels) which is I would then be able to modify using my super fast C image processing functions.  I've been following the "Memory allocation in C with direct access in Actionscript (FAST!!)" section from here.
The problem is that when I allocate the memory in C, then try to display the image using setImage, all I see is a black box on the screen.  The code below shows how I use getPixels to fill the C memory region with my bitmap data, then use setPixels to fill the BitmapData object which is displayed on the screen.  Does anyone know what I'm doing wrong here?  I've been really stuck on this
ActionScript variables, and event function which runs after my Bitmap is loaded
        private var _dataPosition:uint;
        private var displayedImage:Image;
        private var bmp:Bitmap;
public function loaded(e:Event):void {
            bmp = e.target.content as Bitmap;
            // A setImage at the beggining of this function properly displays my image
            displayedImage.setImage(bmp.bitmapData);
            var loader:CLibInit = new CLibInit();
            var lib:Object = loader.init();
            var ns:Namespace = new Namespace("cmodule.alchemyrgr");
            var byteArray:ByteArray = (ns::gstate).ds; //point to memory
            var tmpByteArray:ByteArray = new ByteArray();
            var imgSize:int = bmp.width * bmp.height * 4;
            _dataPosition = lib.initByteArray(imgSize); //This is the position of the data in memory           
            var bounds:Rectangle = new Rectangle(0, 0, bmp.width, bmp.height);
            tmpByteArray = bmp.bitmapData.getPixels(bounds);
            byteArray.readBytes(tmpByteArray, 0, imgSize);
            byteArray.position = _dataPosition;
            bmp.bitmapData.setPixels(bounds, byteArray);
            displayedImage.setImage(bmp.bitmapData);
            //lib.clearByteArray(); //Free the bytearray
C memory allocation function
static AS3_Val initByteArray(void* self, AS3_Val args)
    AS3_ArrayValue(args, "IntType", &bufferSize);
    //Allocate buffer of size "bufferSize"
    buffer = (unsigned char*)malloc(bufferSize*sizeof(char));
    //return pointer to the location in memory
    return AS3_Int((int)buffer);
Thanks in advance!
Mark

Hi Mark,
I too attempted to use a method similar to yours to no avail. I posted my solution for passing bytearray data to/from alchemy here:
http://forums.adobe.com/thread/773517?tstart=0
There is full flash code and C++ code so you should be able to answer all your questions just by reading my post. However, one thing I see about how you're passing your pointer back to flash is:
    //return pointer to the location in memory
    return AS3_Int((int)buffer);
I think should be:
    //return pointer to the location in memory
    return AS3_Ptr(buffer);
You shouldn't be casting your char array as an int and returning it, just use AS3_Ptr(buffer) and that will return the actual memory address as an int to flash. I'm not 100% sure but I think this could be an issue. I use this method also in my code you can find in the link above so you can see the full implementation there. Hope that helps.

Similar Messages

  • If i remove i-tunes then re-install it will i loose all my music? I accidently removed bonjour now can't use remote., If i remove i-tunes then re-install it will i loose all my music? I accidently removed bonjour now can't use remote.

    If i remove i-tunes then re-install it will i loose all my music? I accidently removed bonjour now can't use remote., If i remove i-tunes then re-install it will i loose all my music? I accidently removed bonjour now can't use remote.

    Hello Footr,
    The following article provides the answer to your question, as well as steps for completely removing iTunes and related components:
    Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7
    http://support.apple.com/kb/HT1923
    iTunes Store purchases or songs imported from CDs are saved in your My Music folder by default and are not deleted by removing iTunes. While it is highly unlikely that you will lose any contents of your iTunes Library when following these steps, it is always a good idea to ensure that your iTunes library is backed up. If you're unsure how to backup, see iTunes: Back up your iTunes library by copying to an external hard drive.
    Thanks,
    Matt M.

  • How can I measure memory allocation of a Java Application?

    We built a web application that enables images to be loaded into a database through a servlet running on Tomcat. We have inconsistent behaivor when more than x number of people are loading images simultaneously. No doubt a memory allocation problem, but how can I measure it?
    For example, I'd like to be able to create a graph showing the resources used against the number of people making uploads. I am using Linux and Tomcat/Apache.
    I am hoping for something like Memory counters that are available for measurine Windows applications on MS Windows - comes with the Resource Kit. Does this type of tool exist for the Java/Linux market?

    It is difficult to gauge memory usage from a Java application as the JVM handles garbage collection and even if objects are not referenced they might still be sitting in memory until the next garbage collect.
    Anyhow, a way to query available memory is:
    Runtime.getRuntime().freeMemory()
    You can run this at the begining of a process and at the end and examine the difference. You should call System.gc() before each freeMemory() call in order to try to force garbage collection.
    Another method would be to turn to the underlying OS. On linux you could use 'top' or 'ps'. With ps you could do something like:
    ps -o rss,vsz,%mem <pid>
    Where <pid> is the parent Tomcat process' id. The resulting three columns are:
    - Amount of real memory used.
    - Amount of virtual memory used.
    - Percentage of real memory used.
    'man ps' wil give you more options on how to use ps.
    There are also fancy graphical stuff like 'gtop' as well.
    Hope this helps.

  • Can't get Memory allocation, FPS, ActionScript, ...

    Hello,
    I'm using Flash Develop 4.4.2 with Flash Player content debugger 11.7
    I enabled avanced telemetry with a pluging but in Adobe Scout I didn't get Memory allocating, actionscript, etc.
    I also enabled Memory allocating, actionscript and the Advanced telemetry is enabled in Adobe Scout session.
    I succeed to get the memory allocating just 1 time at the first session but now I got nothing.

    Thanks for the response Michael.
    Hmmmm, weeeeird, just tried it again and it works! Notice in the previous screenshot that "Memory Allocation Tracking" was checked but yet "Disabled" on the Session Info panel.
    The thing that got it to work was checking the "Stage 3D Recording" setting and then turning it off. However, notice in the following screenshot that although unchecked, the Session Info panel still has Stage 3D Recording as "Enabled".
    I dunno, it works now.
    Thanks again for the help/knowledge.

  • Satellite L670-DX1 - after SP1 installation can't use memory card reader

    Hi
    Since I have upgraded my Satellite L670-DX1 from Win7 64Bits to Win7 64 bits SP1 (2 days ago) I can't use my memory card reader anymore, it always says it is a bad card and I should better reformat the card, with any card.
    Does anyone have a similar problem or even better a solution for me?
    Greetings

    yes i have installed sp1 using windows updater, i have tried to let the laptop search for new drivers, and i have the newest, i can't role it back because some virusscanning software makes it fail (allthough i made them inactive after cutting the wireless connection and before putting the old configurations back)

  • Can't increase memory allocation

    For a previous question it was recommended that I allocate more memory to an application. However, when I attempt to do that with Get Info, I only get the options of "General Information" or "Sharing". "Memory" is never listed. Any ideas on what I'm doing wrong?

    Under General Information, check what the file's kind is listed as; if it is 'application program package', control-click it and choose Show Package Contents. Open the folder Contents and then MacOSClassic, or MacOS if there isn't a MacOSClassic folder. Inside this folder, locate the application and increase the memory allocation.
    (9936)

  • Can I use Apple TV in friend's home & then again use in my home as before?

    Can I use Apple TV in friend's home &amp; then again use in my home as before?how?

    Yes. You would set it up the same way you do in your home.

  • Can I use memory from my old G4 laptop in a new iMac?

    My old PowerBook G4 (PowerPC) just died and I know that I have some extra RAM installed in it that I can remove.  Last year, I bought an iMac and would love to be able to use my old RAM in my iMac - will the Intel iMac be able to support my old PowerPC RAM that was in my laptop?  What about my MacPro at work running Mac OSX 10.7.4?
    I'm just not sure if the new hardware in the iMac/MacPro will be compatible with the older hardware from my PPC.

    You can go to http://www.everymac.com and look up the memory in the old Mac and the new and compare, but the answer is going to be no, the older memory will not be compatible with the new iMac.  Different modules, chips, speed, etc.

  • Can i use memory faster than ddr400

    I have a 865pe ne2-ls board, and i want to know if it's possible to use fast ddr, like Kingston Hyperx ddr500??

    Quote
    Does anyone know if it is safe to you a ram say 500 Mhz and then set the motherboard to overclock it at that speed? I mean for the mainboard is it safe?
    Your best performance is with cpu and memory operating at a 1:1 ratio. So to overclock the ram by 25% (400 -> 400) means a 25% overclock on the CPU (200 FSB -> 250 FSB). This is more easily achieved using slower CPU's. With the faster cpu's you may have to use supplemental cooling, raise the operating voltage, or simply not be able to do it. The board will be ok - the question is will the cpu be ok.

  • Can I use Remote app on iPad to control RENTED (read Rented) movies on Apple TV?

    I use the Remote App on my iPad to control movies on my Apple TV, but those are movies that I own and are resident on my home network.
    What about controlling a rented movie that is aquired through iTunes Store? I would like to be able to control rented content just the same.
    Please advise?
    I have the older version of Apple TV – maybe controlling rented movies with ipad can be done with newere Apple TV and iOS 5 on all devices?

    Ok, thanks, now I see the very inconspicuous little "control pad" icon in bottom right corner of Remote App. How the **** is a guy supposed know what that means? Why not just put a button labled with "Control Pad" or something on it?
    Thanks just the same. Now that I know that, it works really slick. I can start/stop/pause rented movies and use my iPad as remote touch pad to navigate anywhere on the Apple TV menu. Nice.
    Can't wait for the "real" Apple TV set to come out.

  • Can I use Word for Mac 2004 to write basic solver/Macros programs?

    I just bought the new macbook aluminum unibody. I am in college and am taking computer programming in fall, I need to be able to write basic programs that utilize macros and solver. I spoke with one mac person who told me I would need to buy parallels, the microsoft OS and then microsoft word for Microsoft OS.
    However, that costs upwards of 200$ for a class I am only going to be taking for 2 months. Someone else has told me that the 2004 version of Word for Mac has macros abilities on it (those that are not on the current version, but that the 2011 version will have). Can I just use the 2004 version? Or does anyone have other suggestions?

    Office 2004 and Other Applications Don't Work in Lion/Mountain Lion
    If you have Office 2004 which is a PPC-only suite, it will not work in Lion/Mountain Lion. You need to upgrade to Office 2011 - Mactopia - or you can try the freeware suite, Libre Office, that is functionally similar to Office 2007 for Windows except it works on Lion/Mountain Lion.
    You may want to consider as well:
    These two suites are similar to Libre Office but not as current or as well-supported:
    NeoOffice
    Open Office
    And, then there is Apple's iWork suite:
    Pages - word processing and layout
    Keynote - presentation
    Numbers - spreadsheet
    Each can open and save Office compatible files. They may be purchased separately via the Mac App Store for $19.99 each.
    As for other software, any PPC-based software will not run in Lion or Mountain Lion because Rosetta is no longer part of OS X. You will need to upgrade to Intel versions of the software.
    (Access to the Mac App Store requires Snow Leopard 10.6.6 or higher and an Apple ID.)

  • Can I use 4k footage in a 1080p sequence, then export 4k without resolution loss?

    Hi,
    I cut a 1080p sequence using 4k footage that I scaled down in the Effect Controls window. If I export that sequence as a 4k file, will Premiere compress that original 4k footage to 1080p, then expand it back to 4k in the exported file (please say no)? Or is Premiere intelligent enough to interpret the export scaling using the size of original footage, rather than the sequence size? (Hope that makes sense)
    Of course it's wise to create a sequence based on your delivery requirements, but sometimes clients change their mind and I don't feel like rescaling every damn clip. But thanks for the advice
    Thanks!
    David

    Premiere will export to the settings of the timeline / sequence you've created.  It doesn't matter what formats you've used withing that timeline.  So if you use 4k in a 2k sequence, Premiere sees it as a 2k sequence and, without user intervention, will export at that format.
    Obviously you can up-scale during export but i) why would you want to do that when you've previously down-scaled and ii) anything above 100% magnification will begin to pixelate.

  • How Can I Use Both Drives in DUAL DVD Writer Setup In G4 Mirror

    I just installed 2 LG 20X DVD Writers in a G4 Mirror. I can operate each individually fine from Toast 8 and Finder. But what I am wondering, is there a way to write simultaneously to both drives? i.e. I load a disc image, and copy it to both drives at the same time.
    Any advice or suggestions would be greatly appreciated.
    Thanks
    Gary

    Hi, Smokerz
    Which version of Toast are you using? I am using v8 and when I start the burn on the first disc ALL menu options are grayed out. Also, Toast totally freezes up: sits on "Writing "<dvd name>" and never does anything. I have to KILL Toast and restart the Mac to kill the burn. When I check the DVD, it is still usable so it was not even initialized.
    BTW - Both drives Master and Slave are seen by Toast and can be selected from the popup by the burn button.
    However, Finder has no problem at all in burning a DVD - it defaults to the Master for the first disc and slave for the second disc. All I have to do is create a Burn folder for each drive and launch Burn Disc one a time! Works create!!
    Any thoughts?
    Thanks
    Gary
    Message was edited by: Gary Sumlak

  • Can you use ipad to back up photos and then remove them from iphone?

    I have a 16gb iphone which is reaching its usage limits.  I also have a 120gb ipad and want to use this to store my photos in order to free up space on my iphone.  Is it possible to set this up?

    Solomon.may wrote:
    Thanks for the response.
    I do not yet have IOS8 due to the lack of space on the phone.
    Update via iTunes, it requires much less space than trying to do it over the air.
    However, I presently have sufficient space on the icloud.  If I delete a photo from my camera roll will it fee up space and allow me to retain them on photostream?
    It will free up space, but not enough, hundreds will need to be deleted. Read my previous post.

  • How can I test a cFP-Vi included FP write- and read-Vi's without cFP-Hardware?

    Can I simulate the cFP-Hardware?
    Without Hardware the Vi will generate an error: "the network module is not powerd on" and the Vi will not be started.

    It is not currently possible to simulate FieldPoint ethernet hardware for use with the FieldPoint VI's.
    Regards,
    Aaron

Maybe you are looking for