Question

I need to initialize string with quite big (over 44K) text and then read sequence of 5-symbol substrings from it. Haxe compiler throws compilation error something like "stack overflow, too complex source" if I do this as initialization for static string variable.

I am using cpp haxe environment, so I can't rely on nice Assets class of openfl framework. And I really don't want to mess up with runtime filesystem operations.

Is it possible to include some external files as data sources (Strings or may be Bytes) to the project and get simple access to this data?

Was it helpful?

Solution

This doesn't seem to be a problem of Haxe, but a problem with the cpp compiler of visual studio.

I just tried generating a 50000 characters and printing it in cpp and I got this error: " error C2026: string too big, trailing characters truncated" http://msdn.microsoft.com/en-us/library/dddywwsc.aspx

Then I tried to compile it to neko and it worked without problems.

A solution to this problem is splitting a longer string in smaller strings and concatenating them like "piece 1"+"piece 2"+...

Edit: I currently can't test it, but I've been told that similar limitations exist in every compiler

OTHER TIPS

Haxe should be able to handle larger strings that that in it's source, so if you're having issues I'd try to isolate the problem in a small test file (no code other than say tracing the big string), and edit your question here or create an issue on Github.

Another thing worth experimenting with is if your example compiles to neko - it is a very similar target to CPP, but sometimes a glitch will show up on one target but not on another target.

As for managing static imports in a low-complexity way, you could either use haxe.Resource (http://api.haxe.org/haxe/Resource.html), or I have a library called "compiletime" that lets you write static var myBigString = CompileTime.readFile("myBigFile.txt"), and a macro will include it all in the compiled file, as if you had typed it directly into the source code.

I also had this issue. In some cases resources - is is bad idea, since e.g. you will need different implementations for windows/Linux.

I have more good solution.

You can do like this:

 unsigned char openClCode[] = 
 {0x23,0x64,0x65,0x66,0x69,0x6E,0x65,0x20,0x55,0x53,
  0x23,0x64,0x65,0x66,0x69,0x6E,0x65,0x20,0x55,0x53,
  ...
 };

How I know In this case you do not have limits. I just tried to make file with code about 500K. So output header file where this variable located I have about 3 Mb.

You can make small program for convert your strings to header's with "char array's". I uses this good approach for e.g. save my OpenCL code to my applications without any resources and without any additionals files where my OpenCL code located. I just uses C-arrays in C++ program for save my code to my application.

So in my CL application I have like this:

__kernel void TestMul(__global const float* a, __global const float* b, __global float* c, int iNumElements)
{

and in my header file this converted to like this:

#pragma once
namespace Scl
{

const char g_clCode_ProgTestComonent[] =
{
    0x5F, 0x5F, 0x6B, 0x65, 0x72, 0x6E, 0x65, 0x6C, 
    0x20, 0x76, 0x6F, 0x69, 0x64, 0x20, 0x54, 0x65, 
    0x73, 0x74, 0x4D, 0x75, 0x6C, 0x28, 0x5F, 0x5F, 
    0x67, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x20, 0x63, 
    0x6F, 0x6E, 0x73, 0x74, 0x20, 0x66, 0x6C, 0x6F, 
...
};
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top