473,385 Members | 1,531 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,385 software developers and data experts.

Sanity Check; C library memory management through through C#

Does anyone know if there are any ramifications of using crtdll.dll
from within the framework?

[System.Runtime.InteropServices.DllImport("crtdll.d ll")] extern public
static IntPtr malloc(Int32 size_t);

and simmilar will work fine; looking at the source of CLR itself:

ILNativeInt _IL_Marshal_AllocHGlobal(ILExecThread *_thread,
ILNativeInt cb)
{
if(UnmanagedOK(_thread))
{
/* Use the underlying system "calloc", because
"ILCalloc"
may have been redirected elsewhere */
void *ptr = (void *)calloc((unsigned)cb, 1);
if(ptr)
{
return (ILNativeInt)ptr;
}
ILExecThreadThrowOutOfMemory(_thread);
}
return 0;
}

we can can see the functions being used.
To prevent some of the questions; working with real-time buffers i do
need the functions and no, i do not want to implement it in C++ as it
is a very small portion of the project.

What i dont know is where does CLR allocate the memory when low level
is called. Is it local heap to CLR (and thereby possible compromise of
GC's efficiency) or is it separate heap that CLR hosts for unmanaged
functionality.

tia

P.S. While doing some of the testing I got something very puzzling;
declaring functions such as calloc() and free() through above method
and then running 1mln allocations & free i found out that Internal
Marshal.AllocHGlobal & Marshal.FreeHGlobal seems to work at about 5
times faster.
in high resolution timer allocating 20k per loop
~3030000 for Marshal class functions
~12680000 for C functions
for comparison; allocating a single managed structure with the same
amount of bytes (Size = 20k)
~32580000.
Clearly Some of the internal functions win the question is why. I
tried both libraries crtdll.dll and msvcrt.dll

The logic that I'm following: if managed function executes the same C
library, why in the world is direct call slower??

Any responses will be highly appreciated, even lunacy will not be
frown on...
Nov 15 '05 #1
3 1244
Arthur,
and simmilar will work fine; looking at the source of CLR itself:

ILNativeInt _IL_Marshal_AllocHGlobal(ILExecThread *_thread,
ILNativeInt cb)
Which CLI implementation is this? The CLR's AllocHGlobal
implementation calls kernel32!LocalAlloc, no CRT functions.

What i dont know is where does CLR allocate the memory when low level
is called.


What allocation are you referring to, specifically?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2
I stand corrected, AllocLocal/FreeLocal LocalReAlloc is what current
framework is using; I looked at rotor distribution:
http://introspector.sourceforge.net/...8c-source.html
perhaps it is old?

Thanks for the reply.
Mattias Sjögren <ma********************@mvps.org> wrote in message news:<Og**************@TK2MSFTNGP12.phx.gbl>...
Arthur,
and simmilar will work fine; looking at the source of CLR itself:

ILNativeInt _IL_Marshal_AllocHGlobal(ILExecThread *_thread,
ILNativeInt cb)


Which CLI implementation is this? The CLR's AllocHGlobal
implementation calls kernel32!LocalAlloc, no CRT functions.

What i dont know is where does CLR allocate the memory when low level
is called.


What allocation are you referring to, specifically?

Mattias

Nov 15 '05 #3
Arthur,
I looked at rotor distribution:
http://introspector.sourceforge.net/...8c-source.html
perhaps it is old?


That looks like Portable .NET, not Rotor. It's a different CLI
implementation, and it makes sence for it to use something other than
LocalAlloc for portability reasons.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #4

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

Similar topics

7
by: Randell D. | last post by:
Folks, I've heard of buffer overflows being used/abused by hackers and believe one method to reduce this from happening is to check the length of my form data before writing it to my MySQL...
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: 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...
5
by: Leonardo D'Ippolito | last post by:
Hello all. The code bellow prints (in the command line window) the MAC ADDRESSES of all NIC cards enabled in the computer. What I need is: a library based on this code, that will return a...
2
by: Chris Podmore | last post by:
I don't know if this is the correct newsgroup but I couldn't find one for Windows Services Is it possible to check that a Windows Service is still running from another machine The idea being a...
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
6
by: Dan Henry | last post by:
I need a sanity check. The following is an exchange on comp.arch.embedded with CBFalconer in a rather long MISRA related thread. Since my little section of that thread and area of interest was...
20
by: J de Boyne Pollard | last post by:
MThe library functions which are included to allow process Mlaunch, forking, and termination, imply that it is both Mpossible and desirable for a process to fork itself. This is Ma fundamental...
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.