leandro.martins Posted November 29 Posted November 29 (edited) Hi everyone, I am trying to find way to check if the memory being accessed within the user buffer is allocated. I had no success in finding anything in the "PowerPMACCLanguageManual". The PowerPMAC is configured with 1MB, as default. Therefore, when I check through gpascii, I got Sys.Ddata[131072] Sys.Ddata[131072]=nan In C, I would expect that at the same address the pointer would be pointing to NULL, or a NaN in the content. However, that is not the behaviour that I got, being possible to even assign a new value to that address. Here is a test that I have done, running as a background program int main(void) { InitLibrary(); double *ptr = (double *) pushm + 131072; printf("pushm: %p\n", pushm); printf("ptr: %p\n", ptr); printf("%f\n", *ptr); *ptr=123.777; printf("%f\n",*ptr); CloseLibrary(); return 0; } and the output pushm: 0x73833000 ptr: 0x73933000 0.000000 123.777000 Is this the expected behaviour ? Is there a way of getting the same value of memory allocated that when I use the "size" command for the User Buffer? Edited November 29 by leandro.martins Quote
MoMo Posted December 2 Posted December 2 In C, the printf function is used for formatted output. If you use the %f format specifier to print a floating-point variable with a value of NaN (Not a Number), the output may be 0, depending on the implementation environment and library behavior. It is recommended to use standard library functions like isnan to detect and handle special values before printing. Quote
leandro.martins Posted December 2 Author Posted December 2 (edited) Thanks MoMo. I did some more tests about that. This is what I have using isnan : int main(void) { InitLibrary(); int idx; double *ptr; idx=131071; ptr = (double *) pushm + idx; if(isnan(*ptr)) printf("Sys.Ddata[%d] = nan\n",idx); else printf("Sys.Ddata[%d] != nan\n",idx); printf("Just printing the content %f\n", *ptr); idx=131072; ptr = (double *) pushm + idx; if(isnan(*ptr)) printf("Sys.Ddata[%d] = nan\n",idx); else printf("Sys.Ddata[%d] != nan\n",idx); printf("Just printing the content %f\n", *ptr); return 0; } Output Sys.Ddata[131071] != nan Just printing the content 0.000000 Sys.Ddata[131072] != nan Just printing the content 0.000000 IDE's terminal Sys.Ddata[131071] Sys.Ddata[131071]=0 Sys.Ddata[131072] Sys.Ddata[131072]=nan If I actively change Sys.Ddata[131071] to nan, via IDE's terminal, and executing the Capp once again, then I got Sys.Ddata[131071] = nan Just printing the content nan Sys.Ddata[131072] != nan Just printing the content 0.000000 So the problem doesn't seem to be in the printf. I have found a UserGetMem function, but it's not clear to me what are its parameters, and if it does what I'm expecting. If there is any other way of checking the amount of memory allocated for the User Buffer, beside checking the content value, that would be very welcome. Edited December 2 by leandro.martins Quote
MoMo Posted December 2 Posted December 2 NAN_Test.mp4 I did the same test and found no issues. When Sys.Ddata[1] = NaN, Sys.Udata[2] contains its low 32 bits, and Sys.Udata[3] contains its high 32 bits. According to the binary representation of NaN in the IEEE 754 double-precision floating-point standard, the sign bit (S) can be either 0 or 1, indicating positive or negative NaN. The exponent bits (E) are all 1 (i.e., 2047), and the fraction bits (M) are not all 0, with at least one non-zero bit. The above values indicate that it conforms to the definition of positive NaN. Using the C program for detection, it enters the 'P1=1' branch, indicating that it is NaN. Quote
leandro.martins Posted December 2 Author Posted December 2 Hi MoMo, I think I wasn't clear what I'm trying to achieve. I'm trying to guarantee that, for 1MB allocated to User Buffer, from Sys.Ddata[131072], or from Sys.Idata[262144] are not being accessed. For that, as we have a "nan" return when we query those values, I was thinking to use that in my Capp. However, in C they return zero instead. This only occur for those indices (131072 ans 262144). I'm trying to understand why there is that difference between the information obtained via terminal and the C program. If that approach would not be possible for what I'm intending, then I would like some help in finding another way for that. Quote
MoMo Posted December 2 Posted December 2 In C, there are no restrictions on memory access, so the values you retrieve through C are the actual values stored in memory. However, in a scripting environment, you can set constraints on the access range. Therefore, the values in the scripting environment may differ from those in the C environment. Quote
leandro.martins Posted December 3 Author Posted December 3 Thanks MoMo, I think it's clear to me now. So the values defined in 'System>CPU>System>Memory Buffers' are only used for restricting the memory in the scripting environment. Currently I have an application that writes into the USHM, using the script language , and a Capp reading from there. So I will have to change the approach to guarantee that both are writing and reading from the same range . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.