COM library and SAFEARRAY overhead

Hi all,
I have a particular problem that seems to be an issue with labview
that I would like to know if there is a better solution for...
I have a COM DLL that requires the user to pass down a buffer, which
it fills with data and returns to the user. The function is declared
in the COM DLL as follows:
HRESULT FetchData([in, out] SAFEARRAY(float)* DataBuffer, [in] long
DesiredAmount, [out, retval] long* ReturnedAmount);
The overhead of the call itself is minimal and I have additionally
created a test DLL that just fills the buffer with known data and does
nothing else. Debugging statements within the DLL show the call taking
on the order of a few milliseconds even with pretty hefty arrays going
in. Additionally, I've tested the DLL under C++ clients and the entire
overhead of the call (including COM overhead) is still on the order of
milliseconds.
However, when this method is called within Labview, I get some odd
results. Labview shows the type of the first parameter (the SAFEARRAY)
as a Variant, not an array. I thought "no big deal", Labview wrapping
the SAFEARRAY into a Variant shouldn't take any appreciable amount of
time. As a result, it seems the only way to get at that data is to use
the Variant-to-Data block in Labview. Unfortunately, this call seems
to take a very large amount of time. The time it takes seems to
increase exponentially with the size of the array passed in. This
would be sort of expected if we were passing a SAFEARRAY containing
Variants, where each element would need to be individually converted.
However, the SAFEARRAY is declared to contain only floats. There
should only be a fixed (and very small) amount of overhead to access
that data from within the SAFEARRAY.
With this overhead of converting the data we can only seem to push a
few MB a second of data through Labview. Other programs in C++/.NET
can push easilly ten times this when calling the same COM DLL. NI
seems to be saying this is an unavoidable problem with using Variants
and COM, but as you can see our DLL isn't putting anything into
Variants.
To try to increase speed a bit I created a C DLL with the following
method:
BOOL CopySafeArrayToBuffer(VARIANT* pVar, DWORD bytesToCopy, float*
pDataBuff)
Since Labview seems put the returned SAFEARRAY into a Variant, I had
this method take a Varint directly. It simply goes into the Variant,
accesses the SAFEARRAY contained within it, and memcpy's the requested
number of bytes into the raw buffer passed in. I can directly wire
this method to the returned buffer from the COM call. Using this DLL
it improves the speed by at least 100%. I am still sure there may be
overhead passing Labview's buffer into the COM DLL to begin with, so I
may experiment with a DLL call to generate the SAFEARRAY there also to
see if that helps speed more.
Does anyone have any idea why Labview seems to incur so much overhead
when dealing with SAFEARRAYs? The actual overhead of calling the Win32
API calls to deal with them should be insignificant. As long as the
data within the SAFEARRAY is of a single simple type (not Variants) it
should be just as fast to access as a raw buffer that a C DLL returns.
Thanks for any suggestions you have!
-Eric Gross

rolfk wrote:
There is one problem with this. SAFEARRAYS are not directly compatible with LabVIEW datatypes. So what is actually happening is that LabVIEW passes in a variant to the COM library and that takes it and puts in a SAFEARRAY. Then when you try to convert the SAFEARRAY variant into a LabVIEW array what actually happens is that LabVIEW creates a new native LabVIEW array handle and copies all the data from the SAFEARRAY variant into it and then disposes the COM variant altoghether.
There is no way LabVIEW could directly continue to use a SAFEARRAY in its diagram as the according memory management is quite different between COM objects and LabVIEW data types. So this copy is basically inavoidable due to different memory management paradigmas between COM and LabVIEW.
If you new the buffer size needed by your COM DLL beforehand and had a function where you could simply pass a LabVIEW preallocated float* array pointer into, this would be no problem at all.
Rolf Kalbermatter
Rolf:
Thanks for your insight to the problem. I didn't see your message earlier it seems because it didn't go through the forum<->news gateway. I posted that message via the newsgroups and it went through into the NI forums fine, but your response did not come back through the gateway.
The temporary solution we had implemented was basically using a C DLL that took the Variant datatype from COM along with an array and copied the data from one to the other. The C prototype was as below:
SA_CONVERT_API BOOL CopySafeArrayToBuffer(VARIANT* pVar, DWORD bytesToCopy, float* pDataBuff)
This method worked fine, but obviously has a bit of overhead copying the data from one to the other (but it still was easily several times faster than labview's internal variantToData functions.
Now I am trying to use your suggestion of exposing a method on a Labview-specific interface that takes a raw array pointer directly without using SafeArrays. However, I ran into a bit of a problem with this...
Under C, passing an array is the same as passing a single item by reference. Labview sorts out the types by letting the labview programmer manually specify the types of all the arguments to the function. (Note that the C prototype listed as you specify the arguments will look identical whether you specify passing a single item by reference or an array of those items---its up to the programmer to know what the C DLL is expecting).
Our new COM method on this interface is shown below:
HRESULT FetchDataLV([in, out] float* DataBuffer, [in, defaultvalue(0)] long DesiredScans, [out, retval] long* ReturnedScans);
The problem is that Labview thinks the first parameter is a reference to a single item as opposed to an array. Since it is a COM method, there seems to be no way to specify the argument types as you can when calling a C DLL---everything is determined by the type library. Is there any way I can convince Labview that the first parameter is an array of floats rather than a a single float passed by reference?
Thanks for any insight you may have,
Eric Gross

Similar Messages

  • Ipad Remote app works for only half the songs in my iTunes library, and sound still comes out of my Mac instead of my iPad.

    Can anyone offer suggestions? I realize there are two separate issues here.
    1. I thought I successfully connected my iPad with the iTunes library on my Mac/ Hard Drive via the Remote app. However, more than half the songs in my music library will not play on the Ipad; when I click on any one of them using the iPad's Remote app & iTunes, I get a message box that says: "An unknown error occurred. Please check your library and try again." These songs all play fine through my Mac's Itunes program.
    2. I had thought I could use the Remote app to get my library "into"  my receiver, connecting the iPad to the receiver with an RCA-to-headphone adapter. This adapter works great to play music that "lives" on an iPod or iPad.  But it does not seem to be able to access music that the ipad is controlling only remotely. If this is true I will be pretty unhappy...

    Thank you. My two questions have now shifted.
    1. You are right-- I have been unsure as to whether Homesharing or Remote was my answer, and I did set up Homesharing on both my Mac and iPad. It still appears that my music comes out of the Mac, only. How can i use  Homesharing to allow the iPad to play music? 
    2. And I went back to check again, and saw that somehow, the songs that my iPad cannot locate are also somehow missing now on the Mac, even though they used to be accessible. My entire music library is stored on an external hard drive, which I used to connect to my Mac with USB. I just got a new router and now have the music hard drive connected via USB to IT instead of the Mac. I would bet that this is why so much of my library is no longer accessible-- I must have used different settings to save some of my songs, and the hard drive's new location shows that. Can anyone help me make my entire music library playable ? Thanks again

  • I have downloaded cds into my itunes library and want to load them ont my ipod touch.  it is only transferring music that i have purchased.  How come?

    I have downloaded cds into my itunes library and want to load them ont my ipod touch.  it is only transferring music that i have purchased.  I did not have this problem with my iphone or my old ipod touch.  How come?

    Do they play in iTunes on the computer?
    Did you use the iTunes import feature?
    http://support.apple.com/kb/PH12486
    What is the format of the songs? Select a song and right click and select Get Info and go to the Summary tab

  • HT1473 I click "add file to library" and then the song i want, but it doesn't come up

    Im really POed at the new iTunes on so many levels. first, the iCloud makes all songs i bought when i was 11 and deleted when i was 13 again. me and my little sister share the same account, but we have different computers so we don't have each other's song. now, thanks to iCloud, we do. i do not want carrie underwood or justin bieber, abd she doesn't want david bowie and led zeppelin. right now, the icloud isn't working, which is fine right now, but it's not right.
    ok, about "adding music and other content to iTunes." you used to be able to drag a file from your documents to your library and it would be copied onto it. i am under the impression that that isn't the case anymore. I've tried a billion times and it hasn't worked. even when im on the led zeppelin section of my library and i drag "over the hills and far away" it won't budge; there's still only 6 albums and 10 songs. so i clicked "add file to library" and then the song i want, but it doesn't come up. and i did this a zillion times with a bunch of different songs, and nothing.
    another problem is that the files are screwy. "houses of the holy" is on the album physical graffiti, not houses of the holy. if i edit the song's info to physical graffiti, all the other songs that are supposed to be on houses of the holy go into physical grafitti. when i go to song info, they still say houses of the holy. i just tried changing it again, and now all my led zeppeling albums are labeled houses of the holy. WHAT IS THIS MADNESS!?!?!?!?!
    #NewiTunesSucks

    Go to edit-preferences-advanced-
    uncheck 'keep itunes media folder organised'
    Then  make changes and see if itunes keeps the new info...
    But warning! if you allow iTunes to organise your files in the future  these change will be undone I believe.

  • IPhoto asked to upgrade library and has now come up empty even though my iPhoto file is over 130GB.  How do I get back my photos?

    iPhoto asked to upgrade library and has now come up empty even though my iPhoto file is over 130GB.  How do I get back my photos?   I am using OS X Yosemite 10.10.1 with Mavericks.   My iPhoto is 9.6.   I am very concerned as this file has all my photos for the last 15 years!

    If the iPhoto Library is still 130 GB large, your photos are probably still inside; perhaps the library has a corruption.
    Or the iPhoto Library is on drive, that is incompatible with iPhoto. Where is your iPhoto Library stored?
    To check for a library corruption:  Ctrl-click or right-click the iPhoto library and select "Show Package Contents". This will show the folders inside the library package.
    Are there folders called "Masters" or "Old Masters"?
    If there is a folder "Old Masters", you are having a problem with recent bug, that corrupts iPhoto Libraries when upgrading. In that case, it would be best to restore your iPhoto Library from a backup you made before you upgraded to Yosemite.
    Or, if no backup is available, copy the "old Masters" folder to a folder on your Desktop and create a new iPhoto library and import the Old Masters folder.
    If there is no folder "old Masters" try to rebuild your iPhoto Library with the First Aid tools :
    Make a backup copy of your iPhoto Library, but don't overwrite any older backups.
    To launch the "First Aid Tools" hold down the options-command keys ⌥⌘ while double clicking your iPhoto Library.
    Keep the keys held down firmly until the First Aid panel appears.
    Select  "Rebuild Database".

  • I had to reinstall iTunes cause during update it was shut off by mistake, now it won't come up and says,"The file "iTunes Library .itl" cannot be read because it was created by a newer version of iTunes", what do I do?

    I had to reinstall iTunes cause during update it was shut off by mistake, now it won't come up and says,"The file "iTunes Library .itl" cannot be read because it was created by a newer version of iTunes", what do I do?

    Empty/corrupt library after upgrade/crash
    Hopefully it's not been too long since you last upgraded iTunes, in fact if you get an empty/incomplete library immediately after upgrading then with the following steps you shouldn't lose a thing or need to do any further housekeeping. In the Previous iTunes Libraries folder should be a number of dated iTunes Library files. Take the most recent of these and copy it into the iTunes folder. Rename iTunes Library.itl as iTunes Library (Corrupt).itl and then rename the restored file as iTunes Library.itl. Start iTunes. Should all be good, bar any recent additions to or deletions from your library.
    See iTunes Folder Watch for a tool to catch up with any changes since the backup file was created.
    When you get it all working make a backup!
    tt2

  • Ciao, sono sulla mia libreria musica, faccio tasto destro su un brano ma nel menu non c'è l'opzione "Mostra in Finder", come faccio? Hi, I'm in my library and if I click on a track I can't find the option "Show in Finder", why?

    ciao, sono sulla mia libreria musica, faccio tasto destro su un brano ma nel menu non c'è l'opzione “Mostra in Finder”, come faccio?
    Hi, I'm in my library and if I click on a track I can't find the option "Show in Finder", why?

    Hi Mac Attack,
    My computer will not disconnect from the internet.  It seems to find a clone router and continues even when I shut down and unplug my my own home iy
    Your main question was 'chopped' in the title. Please reply in the body of a reply box with the full question and anything you have tried. And no, the long report was not helpful .
    If the same website is opening each time you launch a browser (Safari?) hold down the shift key as you launch to prevent previous pages from opening.
    Have a look at your settings in Safari > Preferences. Especially General and Privacy.
    Reset Safari to remove cookies and other stored data.
    System Preferences > General
    Have a look at your settings in System Preferences >  Security & Privacy.
    Call back with more questions.
    Regards,
    Ian

  • Everytime I attempt to open iPhoto, a message comes up saying, "iPhoto is unable to open this library," and the only option if gives is to quit. How do I get it to open?

    When I select iPhoto to open the application, a message comes up saying, "iPhoto is unable to open this library," and the only option available is to quit. I don't know what library iPhoto is attempting to open, but all I want to do is just start iPhoto over from scratch.

    Hold down the option (or alt) key key and launch iPhoto. From the resulting menu select 'Choose Library' to find out what Library is in question. Use the 'Create Library' option to make a new one.
    To try and repair the damaged one:
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

  • HT4889 When I transferred my data from a 128GB Macbook Air to 256GB Macbook Air (brand new version as of 9/1/13) I end up with 188GB used!   I add up the size of Users, System, Library and Applications and it comes to 90GB.  What am I missing?

    When I transferred my data from a 128GB Macbook Air to 256GB Macbook Air (brand new version as of 9/1/13) I end up with 188GB used!   I add up the size of Users, System, Library and Applications and it comes to 90GB.  What am I missing?  How did I "use" up so much space in migrating from one Mac to another?

    Did you use the Setup Assistant available at the beginning of the new machine's setup process? Or did you use Migration Assistant later after you had set up the new machine?
    If you used Migration Assistant, you generally wind up with two accounts (the new one you set up on the new machine plus the old one you ported over) - that may explain your excessive use of space. In that case, you can either manually combine/remove all unnecessary duplicate files, or you can start over by using Command + R, wiping your drive, and downloading the OS. Once it's downloaded, use the Setup Assistant offered at the beginning of the install/setup process.

  • I have 1428 songs in my itunes library and when i sync to my new iphone it only comes up with 1315 songs have tryed lots of ways but cant seem to get the other remaining songs to it ?? and ideas pls ?

    hello need help pls  bought a 4s and trasferd all my things across including my music but i am missing around 170 songs that wont snyc across ? have tryed taking all songs off and a few other things it seems to be songs that have been in playlists that wint work ? and ideas< cheers

    To import music into your iTunes library on the computer go to iTunes>Help>iTunes Help>Add items to iTunes and follow the instructions
    Delete the "songs" that do not play in your iTunes library and reimport them.

  • When i am in library and click on photos no images come up evendo they come up in projects

    when i am in library in aperture on my macbook and want to see the entire photos in library and i click photos no images appear and no images display in the last week or in the last month. al the photos are in the projects just nothing in photos

    Check to make sure you don't have a filter set in the Photos view
    In the upper right hand corner  of the window make sure the box says Showing All

  • In previous versions of i Tunes you could highlight a song in your library and there would be a genious list on the right side of the screen showing songs like the one highlighted in the library. Now I do not get that list. Is there a way to get this back

    In previous versions of i Tunes I could highlight a song in my library and a genious list would show on the right side of the screen listing songs that were like the one highlighted. Now I do not get that list. Is there a way to get that back?

    Hi again Bob,
    I believe I've found the feature you were speaking about now. Information on the "In the Store" feature of iTunes can be found here:
    Apple - iTunes - Inside iTunes - Using In the Store from within your iTunes Library.
    http://www.apple.com/itunes/inside-itunes/2013/01/using-in-the-store-from-within -your-itunes-library.html
    Thanks for using the Apple Support Communities. Have a good one!
    -Braden

  • How to Restore Library and Playlists to Newly Wiped Hard Drive

    Due to Windows problem, I had to reformat my hard drive.
    Before I did, I copied the entire My Documents folder, including My Music and the iTunes music files and the My Playlist text files to a second hard drive - the D drive - in the same tree structure as they existed on the C drive.
    I do NOT want the music files on the C: Drive - I want the music files on the new D: storage drive. I want iTunes on the C drive but knowing the music files are on the D drive.
    I installed the iPod disc onto the newly cleaned C: Drive and downloaded iTunes ver 6.
    Now I would like to have my iTunes library and playlists back just as they were but I am confused over the ADD FILE and ADD FOLDER commands.
    Add Folder appears to copy the full music files back to the C Drive, which I do not want.
    Add File appears to add the meta data, the library list, and
    the playlists to iTunes, but when you go to play a track, the program says it cannot do so because it can't find the music file. To tell each track the new location of the music file listed means I would have to edit over 1200 line items -- even though I already told the program where the
    music files would be.
    Before trying to add the library and playlists as files, I went into EDIT, Prefences, Advanced and changed the iTunes folder location from
    c:\mydocuments\mymusic\itunes\itunesmusic to
    D:\mydocuments\mymusic\itunes\itunesmusic
    Earlier I had used the Add Folder option and it copied all the music files to the C: drive. I had to delete them and
    try something else.
    What must I do to transfer just the meta data and keep the actual music files on the D drive?
    Dell 8250 desktop   Windows XP  

    The XML file is less important (See the link that Katrina provided above).
    First re-install the iTunes program (if you have not already).
    Make sure that the music folders and files are copied to the exact same location they were in prior to the PC Restore. If they were running on the C: drive, you'll need to place them there at first, then move them within iTunes.
    Then copy the original ITL file you saved into the 'iTunes' folder, replacing the newly created (and smaller) ITL file that was created when you reinstalled iTunes.
    Open iTunes and the Library should be as it was prior to the Restore.
    To move the files to your D: drive keeping iTunes 'informed' see this link:
    http://discussions.apple.com/click.jspa?searchID=721335&messageID=1316838
    Post back if you still have questions.

  • Iphone remote won't connect to my iTunes library and tells me the passcode is incorrect

    My iphone 5 previously worked with the Remote app to control streaming of music from my itunes library to my amp with Airplay capability.  Now it can't find my itunes library and when I go to the Settings for Remote app and try to add the library, it won't accept my passcode on itunes screen where it appears.  I deleted the app and re-added it to my iphone but it still won't work.  My Remote app still works on my Ipad so I'm a bit perplexed as to why it won't work on my iphone 5. Any suggestions?

    Hello dawgfaj,
    Thank you for all the information you provided with the Remote app issue you are experiencing on your iPhone.  I found an article with steps you can take when the Remote app is not connecting to iTunes:
    Remote app for iPhone, iPad, or iPod touch can't connect to iTunes or Apple TV
    http://support.apple.com/kb/ts1741
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • I have 100's of CDs that I have downloaded to my itunes library and they are in the library playable but they do not show up in the C drive under the iTunes Music folder under users.  Why are they in the libary and not in the itunes music folder. Win 7 OS

    I have 100's of CDs that I have downloaded to my itunes library and they are in the library playable but they do not show up in the C drive under the iTunes Music folder under users.  Why are they in the libary and not in the itunes music folder. Win 7 OS.  When I look in the library under the get info screen it says they are in the folder itunes music, under the c: drive but when I actually go to that folder to look for them they are not there....HELP!

    Hello RumDog,
    I think this article will help you find the media in your library.
    Where are my iTunes files located?
    http://support.apple.com/kb/ht1391
    Discovering and changing the iTunes Media folder location
    Note: You would usually only change the iTunes Media folder location to share music between accounts on the same computer. See this article for specific steps on how to accomplish this. Also, see this article if you want to know how to move your music to a new computer.
    Mac OS X: Click the iTunes menu and choose Preferences.
    Windows: Click the Edit menu and choose Preferences.
    Click the Advanced pane. iTunes displays the location of your iTunes Media folder.
    You can then:
    Note where your media folder is, such as for backing up your media.
    Use the Reset button to reset it's location to the default (which is the iTunes folder).
    Click the Change button to select a folder for a new location. Once you change this location:
    If you make a new or alternate iTunes library, the new location will be used by that library.
    Existing files will not be moved unless you choose File > Library > Organize library and choose the option to "Consolidate files."
    From: Where are my iTunes files located?
              http://support.apple.com/kb/ht1391
    Cheers,
    Sterling

Maybe you are looking for

  • My ipod HATES itunes

    Everytime I connect my iPod to my PC it erases all my iTunes. They're still in my iTune library, just not on my iPod. Usually I'll update iTunes or restart my comp and that'll work. But still, this is absolute bull. The funny thing is, I could steal

  • ORA-0605: PL/SQL: numeric or value error: character string buffer too small

    I get this error on two function activities in a workflow of mine. I don't even get into the pl/sql procedure call. The exact error is: Error Name -6502 Error Message: ORA-0605: PL/SQL: numeric or value error: character string buffer too small Error

  • Itunes64.exe (itunes 10.3) - file wont run on my laptop!

    i have just got my new i7 laptop and saved itunes to my downloads and when i run as administrator it does nothing? please help!

  • How to avoid Internet explorer needs for activation?

    Internet Explorer requires me to click one time on the flash movie to activate and use it. But i've seen that on some websites this is not required. Anyone have an idea how to do it?

  • Good way to start with the WM programming?

    I follow "Community Contributions" and I'm testing every new WM what's out there. I know C and I would like to write the WM. How did you learn to write your first WM? What would you suggest to starting WM programmer? Reading Xlib (or others) referenc