Bug? error: code too large

Alessandro71

Well-Known Member
Licensed User
Longtime User
I'm sure it's kind of a corner case, but nonetheless I'm reporting it.
I'm declaring a very large map like this
B4X:
Private Const m_locationsMap As Map = CreateMap( _
    "key1": "value1", _
    "key2": "value2", _
    'another 6000 lines
)
and compiling fails with
error: code too large

I'm surely going to put that table in a SQLite asset database, but is there any hardcoded limit on Map declarations?
 

emexes

Expert
Licensed User
Is a Java implementation limit rather than a B4X limit. Java modules (or perhaps their data segments) can only be up to 64 kB.

 
Last edited:

emexes

Expert
Licensed User
is there any hardcoded limit on Map declarations?
Maps limited only by memory. Map declarations with initial data are limited by Java compiler 64 kB module size limit.

Can you show us a dozen realistic sample lines from your map? If there are only (!) 6000 elements, then it might be possible to still get them embedded into the program rather than having to distribute SQL databases alongside your program.

Another way around the limit would be to have a few LoadMap modules, each less than 64 kB so they don't choke the Java compiler, each adding say 1000 elements to the map. Then in your main program you'd have:
B4X:
Private Const m_locationsMap As Map
Map.Initialize
LoadMap1(Map)    'adds first say 2000 elements
LoadMap2(Map)    'adds another say 2000 elements
LoadMap3(Map)    'adds final say 2000 elements
 

emexes

Expert
Licensed User
wayback machine: suddenly it's DOS era again...
To be fair: most structured programming manifestos advise against subroutines longer than a page or two, let alone ones that compile to 60+ kB šŸ„³

I've only once seen it happen as a result of code itself rather than of embedding data in code, but that example had a *lot* of redundancy in it that could have been factored out, and would have been much more maintainable for it. On the other hand, the program was working fine, and neither of us were in the mood to risk creating new bugs unnecessarily, ie: if it ain't broke, don't fix it.
 
Top