static int allocate(StorageImpl db, int root, int type, BtreeKey ins) 
    {
        int pageId = db.allocatePage();
        Page pg = db.putPage(pageId);
        setnItems(pg, 1);
        if (type == ClassDescriptor.tpString) { 
            char[] sval = (char[])ins.key.oval;
            int len = sval.length;
            setSize(pg, len*2);
            setKeyStrOffs(pg, 0, keySpace - len*2);
            setKeyStrSize(pg, 0, len);
            setKeyStrOid(pg, 0, ins.oid);
            setKeyStrOid(pg, 1, root); 
            setKeyStrChars(pg, keySpace - len*2, sval);
        } else if (type == ClassDescriptor.tpArrayOfByte) { 
            byte[] bval =  (byte[])ins.key.oval;
            int len = bval.length;
            setSize(pg, len);
            setKeyStrOffs(pg, 0, keySpace - len);
            setKeyStrSize(pg, 0, len);
            setKeyStrOid(pg, 0, ins.oid);
            setKeyStrOid(pg, 1, root); 
            setKeyBytes(pg, keySpace - len, bval);
        } else { 
            ins.pack(pg, 0);
            setReference(pg, maxItems-2, root);
        }
        db.pool.unfix(pg);
        return pageId;
    }