473,666 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

large (>2G) addresses

Dear staff
Can I get your assistance with \3GB (LARGEADDRESSAW ARE) switch in mixed mode
process built by VS 2008, please?

I have a mixed mode application: C# GUI calling native C++ DLL through
managed C++ wrapper. And I want to give the native C++ code access to large
(>2G) addresses; but (if it’s possible) I do not want the managed code to use
this extra GB of virtual memory.

Questions are:
1. Do I need to alter the header of the mixed mode C# executable to
activate large (>2G) addresses in native C++ DLL which is built using
LARGEADDRESSAWA RE?
2. And if I didn’t change the executable header would the managed code still
be confined to 2GB space?
3. Does same logic applied to larger (>4G) memory allocation in win32 mixed
mode process?
4. Is there any information (guide) on how mixed mode process handles large
virtual memory?

Your help is appreciated. Sergei

Jun 27 '08 #1
4 5087
Sergei wrote:
Dear staff
There's no staff here, just a bunch of volunteers. (Well, some of the
volunteers *are* Microsoft staff, and some might not even be volunteers, but
that's neither here nor there.)
Can I get your assistance with \3GB (LARGEADDRESSAW ARE) switch in mixed mode
process built by VS 2008, please?
And you don't need to ask to ask.
I have a mixed mode application: C# GUI calling native C++ DLL through
managed C++ wrapper. And I want to give the native C++ code access to large
(>2G) addresses; but (if it’s possible) I do not want the managed code to use
this extra GB of virtual memory.
Why not? If anything the *unmanaged* code might have problems with large
addresses. The managed code should be fine. The CLR has no problem with
large addresses.
Questions are:
1. Do I need to alter the header of the mixed mode C# executable to
activate large (>2G) addresses in native C++ DLL which is built using
LARGEADDRESSAWA RE?
Yes. In fact, /LARGEADDRESSAWA RE has no effect on DLLs other than possibly
to signal to developers that the DLL has been vetted for large address
correctness. Whether or not large addresses are used depends entirely on the
hosting executable. This is really the only scenario that makes sense; a
loaded DLL becomes part of the application's address space, so it has to
handle the same addresses.
2. And if I didn’t change the executable header would the managed code still
be confined to 2GB space?
Yes, as would any other code running in the same address space, managed or not.
3. Does same logic applied to larger (>4G) memory allocation in win32 mixed
mode process?
Your question is ambiguous.
>4G *addresses* are only possible for 64-bit applications. Those are
automatically all "large address aware", since you cannot mix 32-bit and
64-bit code. On a 32-bit system, you cannot have addresses >3G in a 32-bit
application; on a 64-bit system this goes up to 4G. A 32-bit application can
never have >4G addresses simply because that's as much as 32 bits will hold.

Using >4G *memory* is possible for 32-bit applications if they use clumsy
and non-transparent mechanisms like AWE to access the extra memory (since
they don't have >4G addresses, they can't access all the memory at once),
and through some creative uses of memory-mapped files. For 64-bit
applications the memory is allocated as usual, and there's nothing special
about allocating >4G.

Finally, a single *allocation* >4G could only be done by a 64-bit process.
4. Is there any information (guide) on how mixed mode process handles large
virtual memory?
It's really not much different from how unmanaged processes handle it, with
the provision that the managed part should take care of itself, as the CLR
is large address aware (even though managed applications are not marked as
such by default).

--
J.
http://symbolsprose.blogspot.com
Jun 27 '08 #2
Thank you, Jeroen; it was nice of you to walk through all my questions. And
indeed, I had same assumptions with regard to LARGEADDRESSAWA RE in DLL and
calling process. But there is a contradicting observation.

I have a large address aware C++ DLL (Enable Large Addresses is ON) and C#
winform executable whose header is not modified to access large addresses
>2GB and <3GB (dumpbin \headers doesn’t say “Application can handle large
addresses”). The following code running inside of the DLL allows me to query
and to allocate virtual memory at 2GB and < 3GB addresses:

MEMORY_BASIC_IN FORMATION memory_info;
memory_info.Bas eAddress = NULL;
while (VirtualQuery (memory_info.Ba seAddress, &memory_info , sizeof
(memory_info)))
{
// Region is free, and it can be well aligned and big enough: we are done
if (memory_info.St ate == MEM_FREE )
BYTE * m_pDIB = (BYTE*)VirtualA lloc(
memory_info.Bas eAddress // system selects address
, lRegionSize // page size, in bytes
, MEM_COMMIT // allocate a committed page
, PAGE_READWRITE) ; // read/write access

// Recompute BaseAddress
memory_info.Bas eAddress = (char *) memory_info.Bas eAddress +
memory_info.Reg ionSize;
}

And that is how I manage memory for large arrays.

I want to know will managed code be able to fragment the large addresses and
is AWE is a better performance wise approach handling large memory in win32
application.

Cheers Sergei
"Jeroen Mostert" wrote:
Sergei wrote:
Dear staff

There's no staff here, just a bunch of volunteers. (Well, some of the
volunteers *are* Microsoft staff, and some might not even be volunteers, but
that's neither here nor there.)
Can I get your assistance with \3GB (LARGEADDRESSAW ARE) switch in mixed mode
process built by VS 2008, please?
And you don't need to ask to ask.
I have a mixed mode application: C# GUI calling native C++ DLL through
managed C++ wrapper. And I want to give the native C++ code access to large
(>2G) addresses; but (if it’s possible) I do not want the managed code to use
this extra GB of virtual memory.
Why not? If anything the *unmanaged* code might have problems with large
addresses. The managed code should be fine. The CLR has no problem with
large addresses.
Questions are:
1. Do I need to alter the header of the mixed mode C# executable to
activate large (>2G) addresses in native C++ DLL which is built using
LARGEADDRESSAWA RE?

Yes. In fact, /LARGEADDRESSAWA RE has no effect on DLLs other than possibly
to signal to developers that the DLL has been vetted for large address
correctness. Whether or not large addresses are used depends entirely on the
hosting executable. This is really the only scenario that makes sense; a
loaded DLL becomes part of the application's address space, so it has to
handle the same addresses.
2. And if I didn’t change the executable header would the managed code still
be confined to 2GB space?

Yes, as would any other code running in the same address space, managed or not.
3. Does same logic applied to larger (>4G) memory allocation in win32 mixed
mode process?

Your question is ambiguous.
>4G *addresses* are only possible for 64-bit applications. Those are
automatically all "large address aware", since you cannot mix 32-bit and
64-bit code. On a 32-bit system, you cannot have addresses >3G in a 32-bit
application; on a 64-bit system this goes up to 4G. A 32-bit application can
never have >4G addresses simply because that's as much as 32 bits will hold.

Using >4G *memory* is possible for 32-bit applications if they use clumsy
and non-transparent mechanisms like AWE to access the extra memory (since
they don't have >4G addresses, they can't access all the memory at once),
and through some creative uses of memory-mapped files. For 64-bit
applications the memory is allocated as usual, and there's nothing special
about allocating >4G.

Finally, a single *allocation* >4G could only be done by a 64-bit process.
4. Is there any information (guide) on how mixed mode process handles large
virtual memory?
It's really not much different from how unmanaged processes handle it, with
the provision that the managed part should take care of itself, as the CLR
is large address aware (even though managed applications are not marked as
such by default).

--
J.
http://symbolsprose.blogspot.com
Jun 27 '08 #3
"Sergei" <Se****@discuss ions.microsoft. comwrote in message
news:5A******** *************** ***********@mic rosoft.com...
Thank you, Jeroen; it was nice of you to walk through all my questions.
And
indeed, I had same assumptions with regard to LARGEADDRESSAWA RE in DLL and
calling process. But there is a contradicting observation.

I have a large address aware C++ DLL (Enable Large Addresses is ON) and C#
winform executable whose header is not modified to access large addresses
>>2GB and <3GB (dumpbin \headers doesn’t say “Application can handle large
addresses”). The following code running inside of the DLL allows me to
query
and to allocate virtual memory at 2GB and < 3GB addresses:

MEMORY_BASIC_IN FORMATION memory_info;
memory_info.Bas eAddress = NULL;
while (VirtualQuery (memory_info.Ba seAddress, &memory_info , sizeof
(memory_info)))
{
// Region is free, and it can be well aligned and big enough: we are done
if (memory_info.St ate == MEM_FREE )
BYTE * m_pDIB = (BYTE*)VirtualA lloc(
memory_info.Bas eAddress // system selects address
, lRegionSize // page size, in bytes
, MEM_COMMIT // allocate a committed page
, PAGE_READWRITE) ; // read/write access

// Recompute BaseAddress
memory_info.Bas eAddress = (char *) memory_info.Bas eAddress +
memory_info.Reg ionSize;
}
What makes you think the above code allocates memory from the range >2GB -
<3G?
It doesn't, just try to allocate from 0x80000000, you'll see VirtualQuery
will return 0, which means that you are allocating from kernel space!

You can't allocate memory from the virtual address range above 2GB in 32
bit mode without LARGEADDREASSAW ARE, the OS loader uses this bit from the
executable image when he reserves the address space for the process, setting
this bit in a DLL makes no sense.
That means that you enable this for the whole process, which also means that
the CLR can allocate from the extended area, unless you pre-allocate from
0x80000000 early in the process.
Note also that you should have very good reasons to enable this on system
running desktop applications, most probably you will run into issues because
the memory space for the system is now limited to 1GB, LARGEADDRESSAWA RE is
something that only works well for SQL and Exchange servers, provided they
run on dedicated servers.
Willy.


Willy.

Jun 27 '08 #4
Sergei wrote:
Thank you, Jeroen; it was nice of you to walk through all my questions. And
indeed, I had same assumptions with regard to LARGEADDRESSAWA RE in DLL and
calling process. But there is a contradicting observation.

I have a large address aware C++ DLL (Enable Large Addresses is ON) and C#
winform executable whose header is not modified to access large addresses
2GB and <3GB (dumpbin \headers doesn’t say “Application can handle large
addresses”). The following code running inside of the DLL allows me to query
and to allocate virtual memory at 2GB and < 3GB addresses:

MEMORY_BASIC_IN FORMATION memory_info;
memory_info.Bas eAddress = NULL;
while (VirtualQuery (memory_info.Ba seAddress, &memory_info , sizeof
(memory_info)))
{
// Region is free, and it can be well aligned and big enough: we are done
if (memory_info.St ate == MEM_FREE )
BYTE * m_pDIB = (BYTE*)VirtualA lloc(
memory_info.Bas eAddress // system selects address
, lRegionSize // page size, in bytes
, MEM_COMMIT // allocate a committed page
, PAGE_READWRITE) ; // read/write access

// Recompute BaseAddress
memory_info.Bas eAddress = (char *) memory_info.Bas eAddress +
memory_info.Reg ionSize;
}
I have no idea what you're trying to achieve here. Is this just
demonstration code or a simplified version of what you're actually using? It
certainly doesn't compile, and even with the obvious changes it seems pointless.

There's no point in looking for free memory yourself. If you want that, you
should simply pass NULL for the address in VirtualAlloc(). Also, you must
pass MEM_COMMIT | MEM_RESERVE if you want to both reserve and commit memory;
just specifying MEM_COMMIT only works if the memory is already reserved. If
you just want a big region of memory where you can do contiguous allocations
of your own, use MEM_RESERVE to reserve memory and MEM_COMMIT to commit
pages within that region.

I wrote a demonstration program of my own. It does a few VirtualAlloc()s
from both the main EXE and the DLL, freeing each intermediate result. The
results are consistent: the behavior of VirtualAlloc() depends *only* on
whether the executable is marked LAA; how the DLL is marked is irrelevant.
To be certain I repeated the test with a dynamically loaded DLL; the results
are the same.

Here's the output for a 32-bit app running on 64-bit Windows when the
executable is *not* marked /LARGEADDRESSAWA RE:

VirtualAlloc(NU LL, 0x1000, MEM_COMMIT | MEM_RESERVE | MEM_TOP_DOWN,
PAGE_READWRITE) :
7EFA0000
VirtualAlloc(NU LL, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
00520000
VirtualAlloc(0x 01000000, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
01000000
VirtualAlloc(0x 81000000, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
FAILED: Attempt to access invalid address.

---DLL---
VirtualAlloc(NU LL, 0x1000, MEM_COMMIT | MEM_RESERVE | MEM_TOP_DOWN,
PAGE_READWRITE) :
7EFA0000
VirtualAlloc(NU LL, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
00520000
VirtualAlloc(0x 01000000, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
01000000
VirtualAlloc(0x 81000000, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
FAILED: Attempt to access invalid address.
And here's the output when the EXE *is* marked LAA:

---EXE---
VirtualAlloc(NU LL, 0x1000, MEM_COMMIT | MEM_RESERVE | MEM_TOP_DOWN,
PAGE_READWRITE) :
FFFA0000
VirtualAlloc(NU LL, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
00520000
VirtualAlloc(0x 01000000, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
01000000
VirtualAlloc(0x 81000000, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
81000000

---DLL---
VirtualAlloc(NU LL, 0x1000, MEM_COMMIT | MEM_RESERVE | MEM_TOP_DOWN,
PAGE_READWRITE) :
FFFA0000
VirtualAlloc(NU LL, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
00520000
VirtualAlloc(0x 01000000, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
01000000
VirtualAlloc(0x 81000000, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) :
81000000

Results were obtained on Windows Server 2003 R2 x64.
I want to know will managed code be able to fragment the large addresses and
is AWE is a better performance wise approach handling large memory in win32
application.
I don't know what you mean by "fragmentin g" the addresses, but the CLR will
be able to access any memory you can allocate just fine.

As for AWE: don't bother. If you need >4G memory (which is really the point
where AWE becomes necessary) you should move to 64-bit and leave the
restrictions of 32-bit behind you altogether. I'm fairly certain the CLR has
no support for AWE, so managing it would have to be done entirely from
unmanaged code, which negates a lot of the advantages of garbage collection
(a big plus the CLR offers). Performance is not the issue here: simply being
able to use memory at all is.

--
J.
http://symbolsprose.blogspot.com
Jun 27 '08 #5

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

Similar topics

46
3502
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved by pointer in C++, is there such way in Python? Thansk in advance. J.R.
36
6368
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but something I'll need in this case is some experience-based set of rules about how to use python in this context. For example... is defining readonly attributes in classes worth the hassle ? Does duck-typing scale well in complex
1
2465
by: Juergen Marsch | last post by:
Hi, writing files > 2G with standard library iostream classes results in "... file size limit exeeded." Compiling my program with "-D_FILE_OFFSET_BITS=64" doesn't make any difference. If you know a solution, please tell me. Thanks, Jrgen
24
7116
by: Arno R | last post by:
Hi all, I have a client with several shoe-shops. Customers can leave their email-address if they want to be notified when there is a sale. Input is validated with instr() I am checking for @ and . (required) and also checking for spaces (not allowed). But: A LOT (5-10%) of the addresses still are wrong; (provider doesn't exist) or email-address not valid (anymore). When sending bulk-mail its a nasty problem to get the false addresses...
2
3108
by: Hareth | last post by:
VS2003 if i say dim form1 as new form1 form1.show() It opens a new form everytime... But....what if....
3
6626
by: zou | last post by:
there is a file which is very large, we can use stat to get a file size(<2G), struct stat buf; stat("file", &buf); long s=(long)stat.st_size; but stat::st_size is type of off_t(typedef long), so how about a file larger than 2G?
1
1869
by: tommyk | last post by:
I am writing a small program that reads a text file filled with a large number of IP addresses and attempts to add them to IIS so that they will be blocked. For some reason, about one in every five or six ip addresses that I attempt to add to IIS causes an System.Reflection.TargetInvocationException to be thrown. Here is the code that adds the addresses: static void SetIPSecurityProperty(string metabasePath, string member, string item)...
1
2590
dlite922
by: dlite922 | last post by:
I have a select drop down box containing a few concatenated string in PHP. I use smarty html_options, if you must know. Here's what my list looks like: <option label="Arraignment 05/30/2008 05:00 PM 5B" value="1">Arraignment 05/30/2008 05:00 PM 5B</option> <option label="Arraignment 06/15/2008 05:00 PM 5B" value="2">Arraignment 06/15/2008 05:00 PM 5B</option> <option label="Trial 06/30/2008 05:00 PM 5B" value="3"...
45
4429
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
0
8443
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6192
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.