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

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

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!

Jan 13 '06 #1
7 5017
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..."
%%%% <ya***@ieee.org> % 'One Summer Dream', *Face The Music*, ELO
http://home.earthlink.net/~yatescr
Jan 13 '06 #2
hey Yates,

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

Jan 13 '06 #3
hey Yates,

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

Jan 13 '06 #4

"vansky" <hu*********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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.
Jan 13 '06 #5
Jim Langston wrote:
"vansky" <hu*********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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.


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
Jan 13 '06 #6
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?

Jan 13 '06 #7
On Fri, 13 Jan 2006 03:31:48 GMT, Larry I Smith
<la***********@verizon.net> wrote:
1. HLOCAL LocalAlloc( UINT uFlags, SIZE_T uBytes)
Also: LocalFree
2. HGLOBAL GlobalAlloc( UINT uFlags, SIZE_T dwBytes)
Also: GlobalFree, GlobalLock, GlobalUnlock

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)
Jan 13 '06 #8

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

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
11
by: Michael B. Allen | last post by:
Coming from C and Java on *nix I'm a little out of my element messing around with CList and MSVC++ but I think my issues are largely syntactic. I have an ADT that I use called a 'varray' that can...
45
by: Pat | last post by:
Hi, 1. Any faster method (other than for-loop) to initialize array? 2. Does there have similar C++ function to replace C's "fprintf"? Thanks. Pat
9
by: MNQ | last post by:
Hi All I want to use my parallel port of my PC to control some external devices. I am writing a program in ANSI C using the PacificC compiler. What I need to know is how to access the parallel...
0
by: collinm | last post by:
hi we use linux and c language under bash i do echo -e \\000\\000\\000\\000\000\\001Z00\\002AA LINUX \\004 >/dev/ttyS1 that send command to a led display (alpha sign communication)
3
by: collinm | last post by:
hi i send a command to a led display, the led display is suppose to return me some character i write a string on a serial port void ledDisplayExist() { char msg={'\0', '\0', '\0', '\0',...
12
by: david.brown.0 | last post by:
I'm trying to make a Java program access a parallel port. Java's comm API does not provide me with the control I need. I need to be able to write to the data and control pins and read the status...
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...
27
by: George2 | last post by:
Hello everyone, Should I delete memory pointed by pointer a if there is bad_alloc when allocating memory in memory pointed by pointer b? I am not sure whether there will be memory leak if I do...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.