473,396 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

memory management (vb.net and vb6)

hello,

i am losing memory each time i make this call to a C++
dll (I make frequent calls).

'in VB.Net
Declare Function grab Lib "grabber.dll" _
(ByRef lpBuf As Byte, ByVal lnum As Integer) As Integer

the C++ function is...
DllExport void __stdcall grab(BYTE *bf, long num)
in VB6 everything is ok, no memory leak.
I understand that memory management in VB6 is auto but it
is not
in .net.

What do I have to do in this case? GC.collect does not
help.
Nov 20 '05 #1
8 9289
Hi Chad,

It might be useful if you tell us what grab() does and show how you are
calling it.

Regards,
Fergus
Nov 20 '05 #2
Hello,

grab() grabs DV frames from the camcorder. the C++ is a
DirectShow samplegrabber.

'***
Public class apifunctions

declare.....

public sub grabAviFrames(Byref dvFrames() as byte, Byval
numframes as integer)

Grab(dvFrames(0), numframes)

end class
'***

'main form
dim avicommand as new apifunctions
avicommand.grab(a, b)

appreciate any help

-----Original Message-----
Hi Chad,

It might be useful if you tell us what grab() does and show how you arecalling it.

Regards,
Fergus
.

Nov 20 '05 #3
Hi Chad,

I was hoping for a bit more - the actual declarations, sizes, calls, etc -
not just illustrations. ;-)

Does your data exceed 85K ?
Does grab do any allocation or just use the buffer passed in?
Etc?

You might find it useful to read the following:

An excellent two part article about garbage collection:
http://msdn.microsoft.com/msdnmag/issues/1100/gci/

Insights below the hood. Arrays, Strings, Pointers and Memory.
http://www.codeproject.com/dotnet/arrays.asp
http://www.codeproject.com/dotnet/pointers.asp.
http://www.codeproject.com/dotnet/strings.asp

Regards,
Fergus

ps. In part 2 of the first article there's a link to Figure 1 which uses
JavaScript. It failed on my machine. If it fails for you too, the full link
is http://msdn.microsoft.com/msdnmag/is...I2/figures.asp.
Nov 20 '05 #4
Hi Fergus,
I will definitely go thru those links... thanx..
btw, those are actual codes. i just left out the
unnecessary ones(just too big).
Does your data exceed 85K ? yes, dvFrames is about 120000bytes.
Does grab do any allocation or just use the buffer
passed in?

grab only uses the buffer passed in.

I cut out the following from the help files under
interopservices and memory management (have you seen it?)
seems to give a clue on the problem I am facing)...
but I'm not sure what I have to do to free the memory.

'_________________________________________________ _____
The interop marshaler always attempts to free memory
allocated
by unmanaged code. This behavior complies with COM memory
management
rules, but differs from the rules that govern native C++.

Confusion can arise if you anticipate native C++ behavior
(no memory freeing) when using platform invoke, which
automatically
frees memory for pointers. For example, calling the
following
unmanaged method from a C++ DLL does not automatically
free any memory.

Nov 20 '05 #5
Hi Chad,

|| The interop marshaler always attempts to free memory
|| allocated by unmanaged code

That's why I was asking about what grab() did. As VB is providing the
memory then it is managed memory and is not an issue.

|| || avicommand.grab(a, b)
||
|| btw, those are actual codes.

Lol. 'a' ?, 'b' ?? I don't believe you'd use those names!! :-)

|| dvFrames is about 120000bytes.

The under-the-hood articles about arrays and pointers mentions items
greater than 85K. It says:

<quote>
Large arrays can have a significant performance hit. Any large object that
consumes 85K is placed in the large object heap. Practically speaking, almost
all of these objects are going to be arrays, and possibly some strings,
because very few classes will contain enough fields to exceed that amount of
memory.

Large objects are not compacted, and are only removed in a FULL garbage
collection, containing generation 2. If the large object includes any
finalizers, then at least two FULL garbage collections will be required.

Since FULL garbage collections can be 100 times or more less frequent than
the partial collections, it can take a long time for memory to be recovered.

Thus, a very poor allocation scheme, probably the worst, for a .NET
application would be one that allocates large amounts very frequently for
temporary uses.
</quote>

Maybe this has something to do with it? Is it possible for you to reuse
the same array/arrays ?

Regards,
Fergus
Nov 20 '05 #6
Fergus Cooney wrote:
Hi Chad,

|| The interop marshaler always attempts to free memory
|| allocated by unmanaged code

That's why I was asking about what grab() did. As VB is providing the
memory then it is managed memory and is not an issue.

|| || avicommand.grab(a, b)
||
|| btw, those are actual codes.

Lol. 'a' ?, 'b' ?? I don't believe you'd use those names!! :-)

|| dvFrames is about 120000bytes.

The under-the-hood articles about arrays and pointers mentions items
greater than 85K. It says:

<quote>
Large arrays can have a significant performance hit. Any large object
that
consumes 85K is placed in the large object heap. Practically speaking,
almost all of these objects are going to be arrays, and possibly some
strings, because very few classes will contain enough fields to exceed
that amount of memory.

Large objects are not compacted, and are only removed in a FULL
garbage
collection, containing generation 2. If the large object includes any
finalizers, then at least two FULL garbage collections will be required.

Since FULL garbage collections can be 100 times or more less frequent
than
the partial collections, it can take a long time for memory to be
recovered.

Thus, a very poor allocation scheme, probably the worst, for a .NET
application would be one that allocates large amounts very frequently for
temporary uses.
</quote>

Maybe this has something to do with it? Is it possible for you to
reuse
the same array/arrays ?

Regards,
Fergus


Not to mention that there was a bug in GC for the large object heap in V1.0.
If he isn't runing 1.1 it is quite possible that those objects will never
be gc'd at all :)

Tom Shelton
Nov 20 '05 #7
Hi Tom,

That's interesting. I'm using v1.0 so I shall be aware.

Thanks. :-)

Regards,
Fergus
Nov 20 '05 #8
Chad,
I hope you realize that your grab function only ever returns a single byte
to .NET!
'in VB.Net
Declare Function grab Lib "grabber.dll" _
(ByRef lpBuf As Byte, ByVal lnum As Integer) As Integer
You have ByRef as Byte, the way .NET works is a single byte will be copied
to lpBuf. Or worse you are modifing managed memory in unexpected ways which
is sure to cause engine execution exceptions.
I understand that memory management in VB6 is auto but it
is not in .net. You understand incorrectly! Memory Management is automatic in .NET also.
What changed is finalization (terminate event) is now non-deterministic.

Which means memory management still happens automatically, Finalization (the
"terminate event") just happens at the will of the garbage collector.

Normal C++ memory management is not auto as you need to match each new with
a delete. There is no delete per se in .NET (Dispose is there to release
unmanaged resource it does not effect the memory itself).

You may want to ask this question 'down the hall' in the
microsoft.public.dotnet.framework.interop newsgroup.

Hope this helps
Jay

"Chad" <hs***@singnet.com.sg> wrote in message
news:05****************************@phx.gbl... hello,

i am losing memory each time i make this call to a C++
dll (I make frequent calls).

'in VB.Net
Declare Function grab Lib "grabber.dll" _
(ByRef lpBuf As Byte, ByVal lnum As Integer) As Integer

the C++ function is...
DllExport void __stdcall grab(BYTE *bf, long num)
in VB6 everything is ok, no memory leak.
I understand that memory management in VB6 is auto but it
is not
in .net.

What do I have to do in this case? GC.collect does not
help.

Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Marcelo A. Camelo | last post by:
Hi! I will be presenting Python to an audience of game developers, mostly C/C++ programmers. In my presentation I will talk about using python and C/C++ extension instead of pure C/C++ to write...
0
by: Richard Jones | last post by:
Garbage Collection & Memory Management Summer School 20-21 July 2004, Canterbury, UK The performance of today's memory-hungry applications depends on efficient dynamic memory management,...
2
by: Mikael Sorensen | last post by:
I've written a windows service (VB.NET 2003). When running, it consumes between 20-40 MB memory. How do I optimize the memory usage? I've set all objects to Nothing when I'm done using them. ...
2
by: DANIEL BEAULIEU J | last post by:
Basically i am a student taking an operating systems course which is c++ intensive. Familiar with Java, and so not so familiar with memory management. Looking for suggestions of exercises or web...
9
by: Rafael Charnovscki | last post by:
I can comprehend the basics of that subject (pointers, memory allocation, heap, stack etc), but I am interested to have references with more details. I have some C/C++ books and lots of URLs...
1
by: Rob Nicholson | last post by:
We're developing our first large scale ASP.NET web application and I'm a little concerned over memory usage of aspnet_wp.exe on the development server during testing. The application appears to use...
1
by: trialproduct2004 | last post by:
Hi all, I am having slight confusion regarding memory management in .net. Say suppose i have two application one is in C# and other is in MFC(VC++). Both of this application are using lots...
0
by: erez_acount | last post by:
***************************************************************************** Call For Papers The 2006 International Symposium on Memory Management (ISMM'06) Co-located with PLDI 2006 ...
34
by: jacob navia | last post by:
Suppose that you have a module that always allocates memory without ever releasing it because the guy that wrote it was lazy, as lazy as me. Now, you want to reuse it in a loop. What do you do?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.