Re: Questions about 64bits portability

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



thanks for all these very good feedbacks !

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> a écrit dans le message de
news: kn43o2di3bpdjo3jjtvisvageuc95slgn6@xxxxxxxxxx
See below...
On Thu, 14 Dec 2006 17:36:16 +0100, "Fuochi" <nospam@xxxxxxxxxx> wrote:

Hello,

I am totally newbee in the migration of 32 bits app to 64 bits. I have
some
questions regarding the portability :

is the following code correct under x64 :

1 - in a list control when setting a item data with a base type
========================================
int i=1 ;
listCtrl.SetItemData(0, (DWORD_PTR)i) ;
int k = (int)listCtrl.GetItemData(0) ;
****
As long as you know the value really is only a 32-bit range, then the
above code works
well. Unfortunately, Microsoft is a bit confused about some uses of
length, so they'll
specify things like an 'int' length (thus allowing for negative lengths, a
fascinating
concept for data structures) but if you use sizeof() you will get warnings
about
truncation. In an intelligent world, lengths would have been defined from
the beginning
as size_t values.
****

2 - structure arithmetic pointers
========================
newNameRecord and currentRecord are 2 pointers to a structure class as
function parameters

void funct(mystruct* newNameRecord, mystruct* currentRecord)
{
DWORD dwBufSize = (DWORD)((LPBYTE)newNameRecord -
(LPBYTE)currentRecord)
****
You should use DWORD_PTR here, simply because it is possible in Win64 to
have arrays
longer than 4.2GB. Frankly, I'd tend to avoid any implementation strategy
in which the
above could be written, but that's because I like robustness. The above
code seems
amazingly fragile, and in any case I would tend to use things which are
based on either
MFC collections or std:: collections, and avoid address arithmetic
whenever possible (I
tend to think in a model of managed code even though I write native apps)
****
;


3 - retrieve a value in a byte array
========================
void funct(LPBYTE lpBuffer)
{
DWORD dwSize = (*((DWORD*)lpBuffer));
****
Again, DWORD_PTR or SIZE_T would be a better choice here, but that's
because you have used
the word "Size" in your variable. Anything that expresses a size should
be thought of as
requiring 64 bits. If this is part of a file, the file should use 64 bit
lengths even in
a 32-bit app so that it can be read by a 64-bit app (note that a 64-bit
app could
potentially write files a 32-bit app couldn't read, but in that case you
simply have to
say "data structure too large". If the size is, by its formal
specification, limited to
32 bits, then the above code is fine; in fact, there is nothing related to
64 bits at all
in such a case.
****

The value was stored using :
memcpy_s ( lpBuffer, dwBuffSize, &dwSize, sizeof(DWORD) );
****
How it was stored is irrelevant. What it means is relevant. Bits are
just bits until you
attempt to assign meaning to them.
****
thanks

Cedric


Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


.



Relevant Pages

  • Re: Advanced Forth app techniques
    ... CHIPS is the chip select table for the NMIX-0332. ... In applications where the user interface involves typing Forth words, it's sometimes desirable to have a closed wordlist of user words, so users can't/won't inadvertently type words that could cause trouble. ... The thing is, that you can define data structures to accommodate the natural "shape" of the data, rather than having to mush the data into a predefined structure. ... Arrays can have byte elements, string elements, cell elements, double-cell elements, floating point elements, whatever your app calls for. ...
    (comp.lang.forth)
  • Re: Memory/Resource Performance issue
    ... Even though it is a suggested way to imporove the performance of a CF app, ... > I'll add the dispose calls in for the datasets first thing monday ... Most of the data structures i use are called as local ... >> Alex Yakhnin, .NET CF MVP ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Questions about 64bits portability
    ... I am totally newbee in the migration of 32 bits app to 64 bits. ... int k = listCtrl.GetItemData; ... concept for data structures) but if you use sizeofyou will get warnings about ... lengths would have been defined from the beginning ...
    (microsoft.public.vc.mfc)
  • RE: Memory/Resource Performance issue
    ... >> Alex Yakhnin, .NET CF MVP ... >>> The problem I am seeing now though is that when the app is first started it ... >>> that the native Out of Memory dialog has been produced. ... and then I use data structures to hold the format of each ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Using sysarch specific syscalls in assembly?
    ... I tried to write a little C app that uses sysarch and i386_set_ioperm to gain ... int main { ... static inline void outb (unsigned short int port, ...
    (freebsd-hackers)