Mem checker
Re:Mem checker
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:-
Peter
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);
Re:Mem checker
Yes, of course it will.
Code: Select all
void *ptr;
ptr = (void*) 0;
(char*) ptr + 1000 == 1000;
(unsigned*) ptr + 1000 == 4000;
Re:Mem checker
hi,
according to the GCC and Intel manuals,
POINTERS ARE 4 bytes in size. doesn't matter the type.
or i'm i wrong?
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
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.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?
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++;
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
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
http://www.mega-tokyo.com/os/os-faq-memory.html#determine_memory
Re:Mem checker
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
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
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
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.
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
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
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
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
Peter
Re:Mem checker
Well...I really didn't study it that much, I just c/p'ed it, since the printf was so big.