dll memory allocation issues

Hello

I recently had trouble with a program that calls a dll that I write in C. The dll uses LabView functions for the memory manager to allocate and free memory for a string of Labview in an ErrorCluster.

I know there has been a lot of posts on this topic, but none seemed exactly applies to my case.

At the start of the vi, everything works well in the beginning, only when it ends and restart, LabView crashes. It seems as if LabView crashes as soon as it tries to free memory (amended) of th Errorcluster.

Starngely what it always crashes. The program could be running 2 - 3 times in a row, then fall for the third time.

I managed to reproduce the error in a small program. VI and the dll code are attached.

I hope that I did not lack a post that already addresses this problem.

Thanks for your help/advice

There is nothing intrinsically wrong about changing the string handles in a LabVIEW DLL, but you must confirm to the Protocol.

There is a very likely potential problems with your C code.

Yoou should really ensure good packing your definition of cluster of error with

#pragma pack (1)

#pragma pack()

for 32-bit Windows. Otherwise you can get by with the alignment as LabVIEW for Windows problems use packing byte to its data structures, but your C compiler will probably try to align the code string and the error on the limits of 4 bytes, resulting in your DLL corrupt pointer real string handle bad.

In addition to this your handling and the copy of the Stiring is VERY low and therefore prone to errors.

Instead your SetError() function might look more like this:

MgErr SetError(LVError *thisError, LVBoolean thisStatus, int32_t thisCode, char *thisSource)
{
int newsize = StrLen (thisSource);
MgErr err;

Set status and Code
thisError-> status = thisStatus;
thisError-> code = thisCode;

If (thisError-> source)
ERR = DSSetHandleSize (thisError-> source, newsize + sizeof (int32));
on the other
{
thisError-> source = DSNewHClr (newsize + sizeof (int32));
If (! thisError-> source)
ERR = mFullErr;
}
If (! err)
{
MoveBlock (thisSource, LStrBuf (*(thisError->source)), newsize);
LStrLen (*(thisError->source)) = newsize;
}
return err;
}

and it could be even simpler:

MgErr SetError(LVError *thisError, LVBoolean thisStatus, int32_t thisCode, char *thisSource)
{
int newsize = StrLen (thisSource);
MgErr err;

Set status and Code
thisError-> status = thisStatus;
thisError-> code = thisCode;

ERR = NumericArrayResize (uB, 1, & (thisError-> source), newsize);
If (! err)
{
MoveBlock (thisSource, LStrBuf (*(thisError->source)), newsize);
LStrLen (*(thisError->source)) = newsize;
}
return err;
}

Tags: NI Software

Similar Questions

  • Get the DLL string (memory allocated for DLL)

    Hi, I'm aware there are a lot of discussions around this topic, but there are a lot of variations and I've never used before LabVIEW, and I seem to have a hard time at a very basic level, so I hope someone can help me with the below simple specific test case to put me on the right track before I pull my hair remaining.

    I've created a DLL with a single function "GenerateGreeting". When it is called, it allocates enough memory for the string "Hello World!" \0"at the pGreeting of pointer, copy this string to the pointer and sets the GreetingLength parameter to the number of allocated bytes (in the DLL in the end, I want to use, there is a DLL function to free the memory allocated for this way).

    I created a header file to go with the DLL containing the following line.

    extern __declspec(dllimport) int __stdcall GenerateGreeting(char* &pGreeting, int &GreetingLength);
    

    I then imported the LabVIEW file using the import Shared Library Wizard. That created a "generate Greeting.vi' and everything seems somewhat sensitive for me (although this does not mean a lot right now). When I run the vi, the ' GreetingLength on ' display correctly '13', the length of the string, but "pGreeting out" shows only three or four characters (which vary in each race), place of the string that is expected of junk.

    The pGreeting parameter is set to the 'String' type, the string "String pointer C" format, size currently Minimum of 4095. I think the problem is that the DLL wants to allocate memory for pGreeting; the caller is supposed to pass a unallocated pointer and let the DLL allocates memory for the string the right amount, but LabVIEW expected the DLL to write in its buffer préallouée. How to with LabVIEW? Most of the functions in the DLL in the end, I want to use work this way, so I hope that's possible. Or I have to rewrite all my DLL functions to use buffers allocated by the appellant?

    The vi , header and the DLL are atteched, tips appreciated. Edit - cannot attach the dll or the headers.

    tony_si wrote:

    extern __declspec(dllimport) int __stdcall GenerateGreeting(char* &pGreeting, int &GreetingLength);
    

    Although char * & pGreeting is actually a thing of C++ (no C compiler I know would accept it) and this basically means that the char pointer is passed as a reference. So, technically, it's a double referenced pointer, however nothing in C++ Specifies that reference parameters should be implemented as a pointer at the hardware level. So free to decide to use some other possible MECHANISM that takes the target CPU architecture support a C compiler constructor. However, for the C++ compilers, I know it's really just syntactic sugar and is implemented internally as a pointer.

    LabVIEW has no type of data that allows to configure this directly. You will have to configure it as a whole size pointer passed as a pointer value and then use a call MoveBlock() or the support VI GetValuePtr() to copy the data on the pointer in a string of LabVIEW.

    AND: You need to know how the DLL allocates the pointer so that you can deallocate it correctly after each call to this function. Otherwise you probably create a leak memory, since you say that the first 4 bytes in the returned buffer always change, this feature seems to assign to each run of a new buffer that you want to deallocate correctly. Unless the DLL uses a Windows such as HeapAlloc() API function for this, it should also export a function according to deallocate the buffer. Functions like malloc() and free() from the C runtime cannot always be applied in the same version between the caller and callee, so that calling free() by calling on a buffer that has been allocated with malloc() in the DLL may not work on the same segment of memory and result in undefined behavior.

  • Change the memory allocated for the graphics?

    Hi, I have an Equium A60-181 with graphics ATi Mobility Radeon 7000. For the moment, that this GPU is using 64 MB of my system RAM that result with only 448 MB of RAM (512-64) for Windows. For a video resolution of 1024 x 768 32 bit it's a ridiculous amount of memory since it only really requires 4 MB for this. I'm not interested in games or 3d graphics, so my question is if I can change the memory allocated to recover more memory system?

    see you soon,

    Richard S.

    HI Richard,

    ATi drivers include an improved graphics option devices-> display manager that allows the value of the AMU to change. My SA30 supports load 16 MB, 32 MB, 64 MB and 128 MB.

    The same value UMA adjustable in BIOS Setup Panel.

    HTH

  • Change THE Memory Allocation 6.0.

    I own a 7 '' netbook Sylvania, with 128 MB of RAM and Windows CE 6.0 OS. There the cursor to change the memory allocation between the PROGRAM and the STORAGE, but it won't budge. To get YouTube running on this thing, I need to go 68 MB of RAM allocated to executing programs for about 130 MB, taking storage (use an SD card to make up the difference - easy). Is there a way to unlock the slide or modify the default setting through the registry hive files? I have already made some adjustments with explore in this way and have managed to add a file to it. I understand in hex. Thank you!

    Hello GusCD6,

    The best place to ask your question on Windows CE 6.0 is in the MSDN forums for the development of Windows Mobile. Click here for a link to the Windows Mobile Development Forum.
    They are there, the experts and would be better able to solve your problem of Windows CE and help answer your questions.

    Sincerely,

    Marilyn

  • Maximum memory allocation for HP Pavilion dv7-7010us

    HP Pavilion dv7-7010us
    Windows 7 (64-bit)

    Hello!
    As shown in the topic, I'm looking for the maximum memory allocation for my new HP Pavilion dv7-7010us notebook.

    I am aware that my computer has two memory slots filled a 2 GB DDR3 SDRAM and a 4 GB DDR3 SDRAM.
    If anyone could also tell me the perfect combination of chip (2 x 4 GB, 2x16GB, etc.) to get the maximum memory allocation, that would be much appreciated. Thank you!
    -Angelo

    Hi, Angelo:

    Here is the link to the service manual for your laptop.

    http://h10032.www1.HP.com/CTG/manual/c03221579.PDF

    Supported memory configurations are in Chapter 1, page 4.

    Paul

  • The display of file space of total Information System Page after changing virtual memory allocation?

    I thought that I understood that I could set up a file.sys page on any available partition on Windows, if I wished, for example, to create more virtual memory or move a file to another drive. However the changes I make to my computer are not appearing in the system information, after a reboot - why is - this?

    I have successfully configured internal auxiliary training to take on a pagefile.sys when you use the system advanced settings in the computer file system properties. Page created on the auxiliary drive single file memory is equal to once and a half the size of the physical memory of the computer.

    As I had created a larger file of the Page on the auxiliary drive, I then decided to reduce the Page file on the boot up to 300 MB drive. When I did make changes, I clicked on the set then OK and then I rebooted the entire computer.

    After restarting the computer, I tried to check system information for a summary of the changes I had made to the file Page and virtual memory space and I was disappointed to see that the pagefile on the auxiliary drive does not show upward. Information system had just recorded space Page MB 300 in C:\pagefile.sys file, and there is no trace of the larger Page file that I created on the auxiliary drive. How is that?

    If I go back to the virtual memory window in advanced system settings, it clearly shows I changed two files Page. Yet in Information System shows only the boot Page file drive. How is that?

    I always use Internet Explorer with only 300 MB Page file space, and it works really faster than the default virtual memory allocation, however the system soon slows down after opening about 5 instances of Internet Explorer and the system starts asking to close application windows down to save memory. So why does the system not switch to use the Page file on the auxiliary drive?

    Hello

    Thanks for posting your query in Microsoft Community.

    I suggest you to report this query in TechNet forum for better support.

    https://social.technet.Microsoft.com/forums/en-us/home

    Be sure to visit Microsoft Community, if you have any questions in the future.

  • Graphics memory allocation

    We use the desktop computer intel i3 3220 cpu with operating system windows 7 ultimate 32 / 64 bit os that quantity grafics memory will be allocted to me of my 4 GB of ram? Also please intimate how to check and change the assignment

    Hi Brandon,.

    I suggest you to see the following links on memory allocation works.

    Usable memory may be less than the memory installed on Windows 7 computers

    http://support.Microsoft.com/kb/978610

    http://www.Intel.com/support/graphics/sb/CS-029090.htm

  • I have upgraded to Windows 10 64 Pro and all my apps Adobe has stopped working; I get the popular "MSVCP110.dll is missing" issue; I uninstalled everything, including the creative cloud, rebooted the PC and installed it back again! Same thing! I tried thi

    I have upgraded to Windows 10 64 Pro and all my apps Adobe has stopped working; I get the popular "MSVCP110.dll is missing" issue; I uninstalled everything, including the creative cloud, rebooted the PC and installed it back again! Same thing! I tried this several times. I'm really stuck! Can someone help with how this is solved; I follow online (two solutions) and tried both; not good! No matter what I do, I get the error! The rest of the applications say they are absent from the other files like this; It seems that there is something to do during the installation that keeps this issue alive!

    Run the command to check the file system once:

    https://support.Microsoft.com/en-in/KB/929833

    Also repair Microsoft Redistributable packages from the control panel > programs and features.

    If not installed, download and install the Visual C++ 2013 package.

    Let me know if you need more assistance.

  • Cannot install software due to lack of memory allocated

    I use 4 Fusion on a Mac Book Pro with 4 MB, when I try to install new software via windows, there is only 1 MB of memory allocated and the software requires 2MB, how to adjust the allocation of memory?

    Shut down Windows Virtual MAchine (MAchine virtual menu > Shutdown)

    Click Virtual Machine > settings > processors and memory

    Change the value of memory 2048 MB. Click View all.

    Close the settings window and start windows.

  • Fire of sql require separate memory allocation

    Hello

    So I tried light sql and trying to put things up. I had a question on how data is managed in memory regarding the memory available for sqlfire.

    First of all,-sqlfire has a default amount of memory allocated when we have a home server? I didn't notice settings during server startup to say he could use x amount of memory.

    Also assume that I have 2 members in my cluster (running with 4 GB of memory available) and I have millions of lines that could not fit in available memory. Data would be saturated on the disk?

    See you soon

    -Imran

    You can explicitly set the initial heap and max - heap for the server at startup. Sqlf server aid Fund

    By default, lines are only in memory.

    If you set the initial heap and max heap and there is no more than ability, you will get an exception. If you do not use these parameters, you run the risk of running out of memory server.

    To outflank your tables, you must explicitly create the table with the configuration of overflow. Keys and indexes are still in memory even when overflow you.

  • Oracle 10g, how to determine the memory allocated is healthy or sufficient.

    Hi guys,.

    I have a 10.2.0.5 production database.
    Currently, my server has 8 GB of physical RAM.
    / 3GB is allocated to the SGA and 1 GB for the PGA.
    Let's say a day is needed for the application (for example, weblogic) to increase the pool of connections from 20 to 50.
    How are we able to know if the memory allocated is sufficient for the existing load as well as the increase in workload?
    CPU is altogether would apply us we can generate on the CPU. If the load is low, I assumed is quite safe to increase the connection.
    Please share your experiences of dealing with this situation.

    Thank you

    Chewy wrote:
    How are we able to know if the memory allocated is sufficient for the existing load as well as the increase in workload?

    There are a set of views memory Advisor which will tell you if your memory structures of appropriate size:
    v$ db_cache_advice
    v$ shared_pool_advice
    v$ java_pool_advice
    v$ sga_target_advice
    v$ pga_target_advice
    --
    John Watson
    Oracle Certified Master s/n
    http://skillbuilders.com

  • Virtual machine consumes memory allocated all

    I have 4 ESXi 4.1 on Dell PE R610 servers. I used the installation ISO Dell from their support site media to install ESXi 4.1.

    I noticed that all virtual machines consume all the memory allocated to it.

    In other words, if I look at the memory of all resource allocation the VM is private.

    It has no memory shared to do so.

    I did not make reservations for the virtual machines.

    Someone at - it other ideas as to why this could happen?

    Thank you

    This "problem" has been discussed a lot already, see threads like these:

    http://communities.VMware.com/message/1487356#1487356

    In short:

    ESX 4.x use large memory pages by default. Find duplicates MB 2 pages for GST is almost impossible with them. You can set the Advanced setting mem.allocguestlargepage to 0 if you want to force the use of small pages, but ESX breaks down large pages under contention memory itself.

  • Resizing of the memory allocated to the virtual machine

    Hello

    I use VMPlayer on a XP and Ubuntu invited crowd.

    I was wondering if I could resize the memory of my Ubuntu virtual machine by changing the value of the variable memsize in 512 to 1024 vmx configuration file or if something more complex needs to be done?

    Thank you very much.

    T bar

    Yes, with the Machine virtual shutdown, not suspended, and it's best if you close the VMware product too.

    Also have you looked in the help file in VMware Player? With VMware Player 2.5 (haven't looked at VMware Player 3 yet). ... under... Running VMware Player > configure memory Allocation change

  • Instantiating display objects and memory leak issue

    Hello

    I was wondering if it would be a memory leak...?

    In the constructor...

    -create a parent sprite (let's call it parentSPRITE)

    -this.addChild (parentSPRITE)

    -instantiate a display of your Flash Pro lib object (let's call it testMC)

    According to...

    -parentSPRITE.addChild (testMC)

    In another function...

    -this.removeChild (parentSPRITE);

    -parentSPRITE = null; / / What is happening to here testMC?

    Then call the first function again...

    -parentSPRITE.addChild (testMC)

    This means that several display testMC objects are accumulated in the memory, or testMC have erased from the display list whenever it's parent is destroyed?

    Thanks for your time and your help.

    If you create an instance of mc and add several times to the same or different parents, nothing more than a single instance of mc is created.

    If a parent is that gc would be or not does not impact on the memory allocated for the child, unless there is no way to reference the child except through the parent company.

  • iOS app breaks down at the return of cameraUI - a memory allocation problem?

    Hey all

    try to complete my first application

    When running on iOS, the application crashes SOMETIMES after returning from cameraUI ("use" / MediaEvent.COMPLETE or cancel "/ Event.CANCEL" "").

    When I leave some other applications running on my iPhone 3 g (and not many are open), the problem goes away, which makes me think it is a problem of memory allocation

    in this aspect, can I trust the iOS to leave inactive applications to allocate more memory for my, currently active, AIR application?

    (there is no memory leak)

    This is a version of os running iPhone 3Gs 4.3.5

    the app is made with Flash Pro 5.5 overlaid with AIR 3.1 sdk and deployed by using the "deploy to app store" type (which should be the most free)

    (no crashes on Android or desktop versions)

    someone had this problem of cameraUI or a similar where an application crashes if more then some numbers of applications are open?

    thanx

    Saar

    Hello

    Thanks for reporting the bug. This problem is known to us, and it is currently under investigation. As far as I know, there is no work around.

    Kind regards

    Samia

Maybe you are looking for

  • Laptop turned off

    I have a system off the key is 50564726 someone can help?

  • Satellite L630 (PSK04E) - Fedora 14 don't bot

    Hello world I'm really getting ride of this3 days trying to install fedora 13 and 14I don't know what the problem with this I tried the same CD on CAREB and it works well so?  :| ================ When I put the cd I get the start menu and when I chos

  • iPhone off to 30% of battery and would not turn on until I plugged it?

    I have an iPhone with 16 GB of storage 6.  I never had this problem or a question similar to this one before.  I'm currently updating on iOS 9.2.1. I was walking home from school today and everything trying to remember my mother-in-law, my phone (whi

  • Satellite P300-133 - Hotkey utility for Windows 7

    Hello. Sorry for my bad English.I have a problem with my laptop Satellite 300-133 I installed Windows 7. Then installed the driver that I found. I have not found on utility Hotkey for Windows 7 and I need to install the driver for Windows XP compatib

  • FANS CONSTANTLY RUNNING

    For reasons unknown to me, the fans on my early 2011 MacBook Pro operate at full capacity from the time when I start the computer until I shut it down and sometimes beyond the closure of 15 ". After taking it to the Apple Store, we found that it is n