Alaska Software Inc. - Limitation on size of #DEFINE created array?
Username: Password:
AuthorTopic: Limitation on size of #DEFINE created array?
Salar MadadiLimitation on size of #DEFINE created array?
on Fri, 07 Sep 2007 17:01:52 -0400
It seems that there is a limit on the size of arrays created using a #DEFINE
statement.  We have a #DEFINE statement that creates an array of 292
elements.  If a function uses this array at all, the application crashes as
soon as the function runs.  There is no error handling, no error log or
fatal log and the crash occurs as soon as the function is called - not even
the first line of code runs, regardless of the contents of the first line of
code.

If we change the length of the defined array to 291 elements or less, there
are no problems.

Has anyone else come across this issue?  Any ideas on how to work around it?

Regards,

Salar Madadi
- Latest Developments Inc.
Andreas Gehrs-Pahl
Re: Limitation on size of #DEFINE created array?
on Sun, 09 Sep 2007 02:15:20 -0400
Salar,

>It seems that there is a limit on the size of arrays created using a #DEFINE
>statement.

Actually, the limitation is with the Xbase++ compiler, which can't compile 
code correctly, if it contains an Array definition with a large number of 
literal Array Elements, like: 

#define MYARRAY   {"1st Item", ;
                   "2nd Item", ;
[...]
                   "1000th Item"}

LOCAL aArray := MYARRAY      This line will result in SPT!

The program will either not compile at all -- and the Xbase++ compiler 
"Xpp.exe" might actually crash while trying to compile it -- or the compiled 
executable will crash (without an Error Log of any kind) when reaching that 
line of code. The actual number of array elements possible depends on the 
OS, the Xbase++ version, available memory, and possibly other factors. There 
is actually a PDR, but it's description is inaccurate, at best.

>Has anyone else come across this issue?

Yes, see the thread: "How to make an Xbase++ program quit with no fatal log" 
in the Generic NG, dated: February 4, 2007, started by Roger Donnay. This 
thread also contains a link to the PDR (Number 109-5659), but the PDR 
description is not quite correct/complete. 

>Any ideas on how to work around it?

The only workaround is as mentioned in the PDR: create the Array in a 
different way. Either like this:

aArray := Array(1000)
aArray[0001] := "1st Item"
aArray[0002] := "2nd Item"
[...]
aArray[1000] := "1000th Item"

Or like this, but this way is a little slower:

aArray := {}
AAdd(aArray, "1st Item")
AAdd(aArray, "2nd Item")
[...]
AAdd(aArray, "1000th Item")

Neither one would work well for a define constant, though, as the variable 
name "aArray" is kinda hard-coded. It wouldn't work to initialize STATIC 
variables, either, as they need a literal for initialization. I assume a 
function with a STATIC array would be the best solution:

#define MYARRAY   MyStaticArray()

Function MyStaticArray()
STATIC saArray := NIL
   if saArray == NIL
      saArray := Array(1000)
      saArray[0001] := "1st Item"
      saArray[0002] := "2nd Item"
[...]
      saArray[1000] := "1000th Item"
   endif
return (saArray)

Then all of the following lines would work:

LOCAL aArray := MYARRAY
LOCAL nLen   := len(MYARRAY)
LOCAL cItem  := MYARRAY[300]
LOCAL cLast  := MYARRAY[-1]

Hope that helps,

-- Andreas

---                                                                      ---
  Andreas Gehrs-Pahl              E-Mail: GPahl@CharterMI.net
  415 Gute Street                     or: Andreas@DDPSoftware.com
  Owosso, MI 48867-4410               or: Andreas@Aerospace-History.net
  Tel: (989) 723-9927           Web Site: http://www.Aerospace-History.net
---                                                                      ---
bobbyRe: Limitation on size of #DEFINE created array?
on Sun, 09 Sep 2007 09:59:24 -0500
This are a few way i create an Array that is used often.

FUNCTION myArray()
 RETURN( { "Item1",  "Item2",  "Item3",  ...} )

or

I save the Array Contents to Disk And Reload depends on
how often i use the Array, if i use it often the funtion is used
but if not very often the disk file is used. i started doing this
back in the Clipper days for EXE size but in windows and
Xbase its not an issue.

bobby




"Andreas Gehrs-Pahl" <Andreas@DDPSoftware.com> wrote in message 
news:rajcp97whhf2.199twt5gq3yzx$.dlg@40tude.net...
> Salar,
>
>>It seems that there is a limit on the size of arrays created using a 
>>#DEFINE
>>statement.
>
> Actually, the limitation is with the Xbase++ compiler, which can't compile
> code correctly, if it contains an Array definition with a large number of
> literal Array Elements, like:
>
> #define MYARRAY   {"1st Item", ;
>                   "2nd Item", ;
> [...]
>                   "1000th Item"}
>
> LOCAL aArray := MYARRAY      This line will result in SPT!
>
> The program will either not compile at all -- and the Xbase++ compiler
> "Xpp.exe" might actually crash while trying to compile it -- or the 
> compiled
> executable will crash (without an Error Log of any kind) when reaching 
> that
> line of code. The actual number of array elements possible depends on the
> OS, the Xbase++ version, available memory, and possibly other factors. 
> There
> is actually a PDR, but it's description is inaccurate, at best.
>
>>Has anyone else come across this issue?
>
> Yes, see the thread: "How to make an Xbase++ program quit with no fatal 
> log"
> in the Generic NG, dated: February 4, 2007, started by Roger Donnay. This
> thread also contains a link to the PDR (Number 109-5659), but the PDR
> description is not quite correct/complete.
>
>>Any ideas on how to work around it?
>
> The only workaround is as mentioned in the PDR: create the Array in a
> different way. Either like this:
>
> aArray := Array(1000)
> aArray[0001] := "1st Item"
> aArray[0002] := "2nd Item"
> [...]
> aArray[1000] := "1000th Item"
>
> Or like this, but this way is a little slower:
>
> aArray := {}
> AAdd(aArray, "1st Item")
> AAdd(aArray, "2nd Item")
> [...]
> AAdd(aArray, "1000th Item")
>
> Neither one would work well for a define constant, though, as the variable
> name "aArray" is kinda hard-coded. It wouldn't work to initialize STATIC
> variables, either, as they need a literal for initialization. I assume a
> function with a STATIC array would be the best solution:
>
> #define MYARRAY   MyStaticArray()
>
> Function MyStaticArray()
> STATIC saArray := NIL
>   if saArray == NIL
>      saArray := Array(1000)
>      saArray[0001] := "1st Item"
>      saArray[0002] := "2nd Item"
> [...]
>      saArray[1000] := "1000th Item"
>   endif
> return (saArray)
>
> Then all of the following lines would work:
>
> LOCAL aArray := MYARRAY
> LOCAL nLen   := len(MYARRAY)
> LOCAL cItem  := MYARRAY[300]
> LOCAL cLast  := MYARRAY[-1]
>
> Hope that helps,
>
> -- Andreas
>
> ---                                                                      ---
>  Andreas Gehrs-Pahl              E-Mail: GPahl@CharterMI.net
>  415 Gute Street                     or: Andreas@DDPSoftware.com
>  Owosso, MI 48867-4410               or: Andreas@Aerospace-History.net
>  Tel: (989) 723-9927           Web Site: http://www.Aerospace-History.net
> ---                                                                      ---