import strutils
source = readFile("example.txt")
var lines = source.split('\n')
I'm reading a file into a string, then splitting it into lines.
Is there any way I could convert the sequence to an array so it doesn't take up so much space?
import strutils
source = readFile("example.txt")
var lines = source.split('\n')
I'm reading a file into a string, then splitting it into lines.
Is there any way I could convert the sequence to an array so it doesn't take up so much space?
The size of an array
must be known at compile time so it cannot be used here. I believe more details about your requirements are needed to undestand why seq[T] "take up so much space" for you.
Looking at seq[T] type declaration here it doesn't look like a lot of overhead to me unless 1000s of small sequences are being allocated.
FYI UncheckedArray
exist (see Unchecked arrays) but they are not memory safe and require you to do extra work to use them.