port Win app to Linux Questions: Memory management and OEM Char

V

vansky

Dear all,

im porting a WIN APP to LINUX, and face some problems that r hard for
me to solve, could u dear guys give me some hands?


i'd like to reimplement the following funcs or replace them with other
ways , but i have no idea how to !!


1. HLOCAL LocalAlloc( UINT uFlags, SIZE_T uBytes)

MSDN: The LocalAlloc function allocates the specified number of bytes
from the heap. Windows memory management does not provide a separate
local heap and global heap.

Also: LocalFree



2. HGLOBAL GlobalAlloc( UINT uFlags, SIZE_T dwBytes)

MSDN: The GlobalAlloc function allocates the specified number of bytes
from the heap. Windows memory management does not provide a separate
local heap and global heap.

Also: GlobalFree, GlobalLock, GlobalUnlock



3. LPVOID VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize,DWORD
flAllocationType, DWORD flProtect )

MSDN: The VirtualAlloc function reserves or commits a region of pages
in the virtual address space of the calling process. Memory allocated
by this function is automatically initialized to zero, unless MEM_RESET
is specified.

Also: VirtualFree, VirtualLock, VirtualUnlock



4. BOOL AnsiToOem( LPCSTR lpszSrc,LPSTR lpszDst)

MSDN: Converts all the characters in this CStringT object from the ANSI
character set to the OEM character set.

Also: OemToAnsi, AnsiToOemBuff


thx!
 
R

Randy Yates

I can't answer your questions directly, but you might want to
check out the wxwidgets library and see how they did some of
these things.
--
% Randy Yates % "Bird, on the wing,
%% Fuquay-Varina, NC % goes floating by
%%% 919-577-9882 % but there's a teardrop in his eye..."
%%%% <[email protected]> % 'One Summer Dream', *Face The Music*, ELO
http://home.earthlink.net/~yatescr
 
V

vansky

hey Yates,

i have check thr wxwidgets manual (2.6.1), but found nothing valuable,
:-(
 
V

vansky

hey Yates,

i have check thr wxwidgets manual (2.6.1), but cant find anything
valuable, :-(
 
J

Jim Langston

vansky said:
Dear all,

im porting a WIN APP to LINUX, and face some problems that r hard for
me to solve, could u dear guys give me some hands?


i'd like to reimplement the following funcs or replace them with other
ways , but i have no idea how to !!


1. HLOCAL LocalAlloc( UINT uFlags, SIZE_T uBytes)

MSDN: The LocalAlloc function allocates the specified number of bytes
from the heap. Windows memory management does not provide a separate
local heap and global heap.

Also: LocalFree

This sounds like a plain ol' malloc. Although I don't know what flags does.
I think it depends on what kind of operability you're trying to get here.
2. HGLOBAL GlobalAlloc( UINT uFlags, SIZE_T dwBytes)

MSDN: The GlobalAlloc function allocates the specified number of bytes
from the heap. Windows memory management does not provide a separate
local heap and global heap.

Also: GlobalFree, GlobalLock, GlobalUnlock

I"d probably use the plain ol' malloc here too. Linux has a different
memory model (I believe) so I would let the Linux OS handle it. Unless you
need the specific functionaly this gives you, just use malloc I guess.
AGain, not sure what flags does.
3. LPVOID VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize,DWORD
flAllocationType, DWORD flProtect )

MSDN: The VirtualAlloc function reserves or commits a region of pages
in the virtual address space of the calling process. Memory allocated
by this function is automatically initialized to zero, unless MEM_RESET
is specified.

Also: VirtualFree, VirtualLock, VirtualUnlock

Okay, here you're allocating pages of memory (16k I believe?). If you can't
find anything specific in Linux to do this guess what I would use instead...
yeap, malloc. Again though, you haven't explained what functionality you're
expecting other than allocating memory.

4. BOOL AnsiToOem( LPCSTR lpszSrc,LPSTR lpszDst)

MSDN: Converts all the characters in this CStringT object from the ANSI
character set to the OEM character set.

Also: OemToAnsi, AnsiToOemBuff

I have no clue on this one.
 
L

Larry I Smith

Jim said:
This sounds like a plain ol' malloc. Although I don't know what flags does.
I think it depends on what kind of operability you're trying to get here.


I"d probably use the plain ol' malloc here too. Linux has a different
memory model (I believe) so I would let the Linux OS handle it. Unless you
need the specific functionaly this gives you, just use malloc I guess.
AGain, not sure what flags does.


Okay, here you're allocating pages of memory (16k I believe?). If you can't
find anything specific in Linux to do this guess what I would use instead...
yeap, malloc. Again though, you haven't explained what functionality you're
expecting other than allocating memory.



I have no clue on this one.

As Jim said, the linux memory model is different from Windows.
You can use malloc(). Of course you can also use 'new' in C++
programs.

you can use calloc() when you need blocks of memory that are
zeroed out.

malloc/calloc/realloc are in stdlib.h (aka cstdlib)
as part of the standard lib.

I have ported several large software suites from Windows
to Linux, and many of the Windows API's are replaced by
a much smaller number of standard and/or linux API's.
In other words, the code usually gets simpler.

Larry
 
V

vansky

hey Jim & larry,

thanks a lot,

my thoughs r very close to u.

im porting a large SW too, so i have to find the BEST ways, otherwise
ill face some unpredictable results.

gettimeofday(struct timeval *, struct timezone *) to replace
GetTimeZoneInformation

using timezone info, the following funcs can be solved,

LocalFileTimeToFileTime, This function converts a local file time to a
file time based on the Coordinated Universal Time (UTC).
FileTimeToLocalFileTime

that's right? or any better way?
 
J

JustBoo

I believe these are old relics from the 16-bit days when Windows
actually did have a local and global memory model. All your gui
controls where allocated locally, etc. (Well, mixed with GDI resource
memory... yada. )
As Jim said, the linux memory model is different from Windows.

Bigtime. :)
I have ported several large software suites from Windows
to Linux, and many of the Windows API's are replaced by
a much smaller number of standard and/or linux API's.
In other words, the code usually gets simpler.

I find it "refreshing." Free of all the MicroSkunk extensions and
arcane HANDLES :) and such. A lot of Windows code is just
plain ugly. ( In more ways than one.) :)

Behind every great fortune there is a crime.
- Honore de Balzac (1799-1850)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top