Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a sequence to an array?

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?

like image 538
baranskistad Avatar asked Dec 03 '25 09:12

baranskistad


1 Answers

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.

like image 180
dxb Avatar answered Dec 05 '25 00:12

dxb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!