---
title: account_resize
description: Changes the data size of an account
source_url:
  html: https://thru.org/docs/spec/vm/syscalls/account_resize/
  md: https://thru.org/docs/spec/vm/syscalls/account_resize.md
---

# account_resize

## Overview

The `account_resize` syscall changes the data storage size of an account. This can be used to expand or shrink the account’s data capacity.

## Syscall Code

**Code:** `0x07` (`TN_SYSCALL_CODE_ACCOUNT_RESIZE`)

## C SDK Function

```c
ulong tsys_account_resize(ulong account_idx, ulong new_size);
```

## Arguments

**`account_idx` · *ulong* · **required****

Index of the account to resize. Must be writable by the current program.

**`new_size` · *ulong* · **required****

New data size for the account in bytes. Must not exceed maximum account data size.

## Return Value

Returns a syscall result code:

**`Success` · *ulong***

- `TN_VM_SYSCALL_SUCCESS` (0) - Account resized successfully

**`Error Codes` · *ulong***

- `TN_VM_ERR_SYSCALL_INVALID_ACCOUNT_INDEX` (-8) - Account index out of bounds
- `TN_VM_ERR_SYSCALL_ACCOUNT_DOES_NOT_EXIST` (-9) - Account does not exist
- `TN_VM_ERR_SYSCALL_ACCOUNT_NOT_WRITABLE` (-10) - Account not writable by current program
- `TN_VM_ERR_SYSCALL_ACCOUNT_TOO_BIG` (-12) - New size exceeds maximum allowed
- `TN_VM_ERR_SYSCALL_INSUFFICIENT_PAGES` (-26) - Not enough pages available for expansion

## Resource Consumption

### Compute Units

- **Base cost**: `TN_VM_SYSCALL_BASE_COST` (512 units)
- **Additional cost**: None (size changes don’t directly affect compute cost)
- **Total cost**: Fixed at 512 units regardless of new size

### Memory Pages

- **Page allocation**: New pages allocated from transaction pool when expanding
- **Page deallocation**: Excess pages returned to transaction pool when shrinking
- **Page granularity**: Account data is managed in page-sized chunks
- **Minimum allocation**: Account metadata always requires at least one page

## Side Effects

- **Data size**: Changes the account’s data size to the specified value
- **Memory allocation**: Allocates or frees pages as needed
- **Metadata**: Makes account metadata and data writable if not already
- **Data preservation**: Existing data is preserved when expanding

## Usage Notes

- The new size must not exceed `TN_ACCOUNT_DATA_SZ_MAX`
- When expanding: additional space is allocated and initialized
- When shrinking: excess data is truncated and pages may be freed
- If new size equals current size, the syscall succeeds immediately
- Account must be writable by the current program
- Sufficient pages must be available in the transaction’s page pool

## Memory Management

- **Expansion**: Allocates additional pages from the transaction page pool
- **Shrinking**: May free pages back to the pool (implementation dependent)
- **Page alignment**: Account data is managed in page-sized chunks
- **Data preservation**: Existing data within the new size is preserved

## Example

```c
#include <thru-sdk/c/tn_sdk_syscall.h>

// Resize account data to 2048 bytes
ulong account_idx = 1;
ulong new_size = 2048;

ulong result = tsys_account_resize(account_idx, new_size);

if (result == TN_VM_SYSCALL_SUCCESS) {
    // Account data size changed to 2048 bytes
    // Existing data preserved (up to new size)
    // Additional space initialized if expanded
}

// Check current size without changing it
result = tsys_account_resize(account_idx, current_size);
// This will succeed immediately if current_size matches actual size
```
