Page 1 of 1
Mem checker
Posted: Sat Dec 07, 2002 2:43 pm
by pskyboy
[attachment deleted by admin]
Re:Mem checker
Posted: Sun Dec 08, 2002 10:18 am
by pskyboy
I fixed it
its very weird but if i cast the pointer to a UINT and then add uiMBofMem it works. I guess this must be some quirk in the compiler that causes this.
The Fix:-
Code: Select all
pStartMem = (UINT*)(uiMBOfMem + (UINT)pStartMem);
Peter
Re:Mem checker
Posted: Sun Dec 08, 2002 1:12 pm
by Tim
Yes, of course it will.
Code: Select all
void *ptr;
ptr = (void*) 0;
(char*) ptr + 1000 == 1000;
(unsigned*) ptr + 1000 == 4000;
Re:Mem checker
Posted: Sun Dec 08, 2002 2:07 pm
by Slasher
hi,
according to the GCC and Intel manuals,
POINTERS ARE 4 bytes in size. doesn't matter the type.
or i'm i wrong?
Re:Mem checker
Posted: Sun Dec 08, 2002 2:49 pm
by Schol-R-LEA
Code Slasher wrote:
hi,
according to the GCC and Intel manuals,
POINTERS ARE 4 bytes in size. doesn't matter the type.
or i'm i wrong?
You are correct, provided that you are talking about flat protected mode NEAR pointers. That isn't relevant in this case, however. It's the size of the variable the pointer is referencing that matters here.
Pointer arithmetic in C automagically increments pointers by the size of the pointer's type; that is to say, given the code
Code: Select all
char a[10], *c_ptr;
int n[10], *i_ptr;
c_ptr = &a;
i_ptr = &n;
c_ptr++;
i_ptr++;
If a is at address 0x00001000 and n is at 0x0000100A, then the final values of c_ptr is 0x00001001, but the final value of i_ptr is 0x0000100E, not 0x0000100B. Otherwise, i_ptr would be pointing at one of the bytes in the middle of n[[0]], rather than n[1].
By casting the pointer to unsigned int before adding it to uiMBofMem, it causes it to add the values as unsigned ints, rather than as pointers to unsigned int. The same result can be gotten more easily (I think) by walking through memory with a byte (== unsigned char) pointer instead of an integer pointer. Thus the result of 9 is correct, it's just given in mega-doublewords rather than megabytes (of course, that should be 8MDWs - see below for an explanation of that issue).
From the results you've been getting, Pskyboy, it seems that the results you are getting are high by one Megabyte (or 4 megabytes, as the case may be); this looks to be an off-by-one error of some sort. Most likely, it is incrementing the count before performing the memory check, and then not correcting for it.
I hope this makes sense. CCW.
Re:Mem checker
Posted: Sun Dec 08, 2002 3:41 pm
by jrfritz
You need to do a different way of checking the memory if it is over 64mb...I read that here:
http://www.mega-tokyo.com/os/os-faq-memory.html#determine_memory
Re:Mem checker
Posted: Mon Dec 09, 2002 11:50 am
by pskyboy
Thanks Tom
That's exactly what i am doing i am probing the memory in 1mb steps writing to the top of each meagabyte and checking the write is successful. I have now got a piece of code that works correctly if anyone is interested i will post it.
Peter
Re:Mem checker
Posted: Tue Dec 10, 2002 6:30 pm
by jrfritz
I'd like that code...
Re:Mem checker
Posted: Thu Dec 12, 2002 1:21 pm
by pskyboy
Here is the code for the function that checks the amount of memory. Sorry it took so long for me to post it.
Code: Select all
printf("Checking Memory", 3);
UINT* pStartMem = (UINT*)0x1FFFFC; //Start at bottom of 2mb as we already know we must have 1mb
UINT uiMBOfMem = 0x100000; //Amount of bytes to make up 1mb
UINT uiTestDWORD = 0x506E6978; //Test DWORD to write = Pnix, for Phoenix
UINT uiAmountOfMem = 0x100000; //We know we have 1mb already
//Write to the Highest DWORD in each megabyte to test for amount of memory available
do
{
//Calculate next memory address
pStartMem = (UINT*)(uiMBOfMem + (UINT)pStartMem);
*pStartMem = uiTestDWORD;
uiAmountOfMem = (uiAmountOfMem + uiMBOfMem);
//for(UINT o = 0; o < 0xFFFF; o++);
/*{
printf(o, 1);
}*/
//printf((UINT)pStartMem, 8);
//printf(uiAmountOfMem, 9);
}while(uiTestDWORD == *pStartMem);
return uiAmountOfMem;
Re:Mem checker
Posted: Thu Dec 12, 2002 1:26 pm
by jrfritz
Why do you use a printf that needs a line number?
There is a printf that has all the functions on my site.
It works just like the normal C stdio.h. The functions are in fstdio.h.
Re:Mem checker
Posted: Fri Dec 13, 2002 1:34 pm
by pskyboy
I know
I have seen the FritzOS printf and i don't really like it. i also just wanted to use a very simple printf and its also useful to be able to pick the line to put it on soem times.
Peter
Re:Mem checker
Posted: Sat Dec 14, 2002 10:47 pm
by jrfritz
Really? Why don't you like it?
Have you seed pk0.7.1's printf?
Re:Mem checker
Posted: Sun Dec 15, 2002 12:58 pm
by pskyboy
I looked at it and tried to see how you where doing it so as to write my own and i found it quite hard to follow. I guess im just lazy and can't be bothered to study it long enough to realise whats going on.
Peter
Re:Mem checker
Posted: Sun Dec 15, 2002 1:07 pm
by jrfritz
Well...I really didn't study it that much, I just c/p'ed it, since the printf was so big.