// Copyright 2019 the V8 project authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.functionAlloc(size){letb=newSharedArrayBuffer(size);letv=newInt32Array(b);return{buffer:b,view:v};}functionRunSomeAllocs(total,retained,size){
vararray=newArray(retained);for(vari=0;i<total;i++){letpair=Alloc(size);// For some iterations, retain the memory, view, or both.switch(i%3){case0:pair.memory=null;break;case1:pair.view=null;break;case2:break;}array[i%retained]=pair;}}RunSomeAllocs(10,1,1024);RunSomeAllocs(100,3,2048);RunSomeAllocs(1000,10,16384);RunSomeAllocs(10000,20,32768);