| Bill Allombert on Mon, 10 Aug 2026 10:01:55 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: creating (non)zero vector |
On Sun, Aug 09, 2026 at 11:17:01AM -0400, Max Alekseyev wrote: > Hello, > > I thought that creating nonzero vector (say, of all 1s) like > > allocatemem(2^31); > V = vector(10^8,i,1); Please do not use allocatemem, this is deprecated. Use default(parisize, 2^31) or default(parisizemax, 2^31) > is more efficient than first creating a zero vector and then filling it > with the required values: > allocatemem(2^31); > V = vector(10^8); > for(i=1,#V,V[i]=1); > > In reality, the latter code works fine, but the former one results in "the > PARI stack overflows" error, which is quite counterintuitive. > Is such behavior expected? Yes, in the second version, the vector components are stored outside the PARI stack. Note that the first version is twice faster and use much less total memory actually. ? V = vector(10^8,i,1);0; *** Warning: increasing stack size to 4000002048. *** last result computed in 2,820 ms. ? getheap() %2 = [24,400004690] ? V = vector(10^8); for(i=1,#V,V[i]=1);0; *** vector: Warning: increasing stack size to 1024000000. ? ## *** last result computed in 9,206 ms. ? getheap() %2 = [100000024,1200004690] Cheers, Bill.