Maximum String length

Discussions about Coding and Scripting
Post Reply
User avatar
Posts: 1771
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Maximum String length

Post by Barbie » Sun Mar 27, 2016 4:37 am

A few moments ago I wondered why my UnrealScript code gives different results to that shell code of duplicate actors. So I wanted to log the string containing all Actor names and boom: SIGSEGV - Aborting - Exiting.

Then I tried just logging the raising string length:
ucc.init.log wrote:[...]
Signal: SIGSEGV [segmentation fault]
In "modern" 32 bit environments strings are usually limited to 2^8 or 2^31 (for ASCII, not UniCode or double byte strings). What about strings in UScript?
code resulting in SIGSEGV

Code: Select all

foreach AllActors(Class'Actor', A)
	if (InStr(s, ":" $ A.Name $ ":") >= 0)
		if (bListDuplicates)
			log("CheckDuplicateActors: Actor" @ A @ "has duplicate name");
		s = s $ A.Name $ ":";
		log("Len(s)=" $ Len(s));
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett

Posts: 1786
Joined: Sun Mar 04, 2012 6:47 pm

Re: Maximum String length

Post by Higor » Sun Mar 27, 2016 6:00 am

How much memory can you allocate in a single chunk?
Unix TCHAR's in UT are 1 byte, Win32 TCHAR's are 2 bytes long.

FString is a TArray<TCHAR> derivate with special methods.
TArray is a 12 byte structure with the following elements:
- Data pointer
- Current max index
- Allocated max index
When going above the allocated max index, it is necessary to reallocate the Data pointer using a bigger chunk, and copying the memory from the old chunk into the new one in order to have contiguously mapped memory.
Reallocating consists on creating a new memory block first, so you're potentially using twice as much memory as what you need in these cases.
Memory will fragment physically via abundance of programs or virtually in the same program by allocating multiple chunks.
If the OS's kernel cannot grant you a contiguous amount of physical memory to be mapped in a single virtual memory space, the reallocation will fail and the pointer will become NULL.
Trying to access a NULL pointer will cause a segmentation fault.

This reply is as simple I'll go, feel free to research how the OS's kernel does it's stuff.
During my experimental port of Gothic game into Unreal 227 I managed to create 60k char strings (WinOS) in a 64 bit Win-XP system with 2gb physical memory.
Image unreal://
Image unreal://

User avatar
Posts: 4328
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Maximum String length

Post by sektor2111 » Sun Mar 27, 2016 9:57 am

That's why I have requested another suggestion and that code posted by Barbie did not fascinated me. Yes, I log all duplicates just to know what I have to do in Editor and simple broadcast On screen "Duplicates/2", if is not accurate I won't be disturbed, it's just a matter of finding trash Levels rather than recording any tiny 0 relevant thing.
As I recall you have 255 chars Length for strings so your function won't help in scanning levels with 3000-4000 actors. Perhaps it works in Levels with 10 actors... I went over 10000000 iterations by writing a state (I did not made such many things before). First time I was wondering if state won't mess something in a mutator but a few seconds later I have a recall about MapVoteLA which USES state - and less magically I solved that 1500-1700 map-load crashy limit due to this experiment with duplicate actors finder which I could do... and which works after all.

Post Reply