3. Memory and Nintendo 3DS Game Cards

This chapter describes memory regions that can be accessed by applications and Nintendo 3DS Game Cards written to by card-based software.

3.1. Memory

3.1.1. Memory Map

The following figure shows a memory map as seen by applications. This memory map is for release versions.

Figure 3-1 Memory Map (Release Versions)

Reserved Region 0x0000_0000 0x0800_0000 Heap Memory nn::os::GetHeapAddress() nn::os::GetHeapSize() 0x0E00_0000 Reserved Region VRAM nngxGetVramStartAddr(NN_GX_MEM_VRAMA) nngxGetVramEndAddr(NN_GX_MEM_VRAMB) nngxGetVramStartAddr(NN_GX_MEM_VRAMB) nngxGetVramEndAddr(NN_GX_MEM_VRAMA) VRAM-A 3 MB 1.5 MB which cannot be used for display buffers VRAM-B 3 MB 1.5 MB which cannot be used for display buffers 0x2000_0000 0x3000_0000 device memory nn::os::GetDeviceMemoryAddress() nn::os::GetDeviceMemorySize() 0x4000_0000 Can be directly overwritten by the application Cannot be directly overwritten by the application

Memory access from applications is carried out using virtual addresses.

For security reasons, it is not possible to execute data arrays loaded into memory other than the region where the program is loaded (such as heap memory or device memory).

Memory above address 0x4000_0000 is reserved.

3.1.2. Device Memory

Device memory is a region in memory for which the OS guarantees address integrity when it is accessed by the GPU or other peripheral device. Some of the buffers accessed by the GPU used for graphics and the DSP used for sound must be allocated from this device memory. Conversely, some buffers cannot be allocated from device memory. Generally, those buffers must be 4096-byte aligned and have sizes that are multiples of 4096 bytes.

You can use the nn::os::SetDeviceMemorySize function to specify the size of the memory region to allocate as device memory. Specify the size as a multiple of 4096 bytes. On CTR, you can allocate up to 64 MB for the main program and heap memory (96 MB on development hardware). On SNAKE, you can allocate up to 124 MB (178 MB on development hardware). You can call this function again to change the size of the memory region to allocate, but if you do you must change the size by a multiple of 1 MB (1,048,576 bytes). There is no guarantee that the address of the memory region allocated will be the same for every call. After specifying the size of the region, first use the nn::os::GetDeviceMemoryAddress function to get the starting address of the region, and then access the device memory. Use the nn::os::GetDeviceMemorySize function to get the size of the currently allocated memory.

Table 3-1. Types and Starting Address Alignment for Buffers Allocated From Device Memory

Device

Buffer Type

Alignment

Comments

GPU

Texture image

128-byte

 

Vertex buffer

1-byte to 4-byte

Changes depending on vertex attributes.

Display buffer

16-byte

 

DSP

Sound source data

32-byte

The size of the whole region storing sound source data must be a multiple of 32 bytes.

CAMERA

Receive buffer

64 bytes (recommended)

If you use a buffer allocated in a space other than device memory, the SDK stops on a panic.

Y2R

Image data receive/send buffer

64 bytes (recommended)

If you use a buffer allocated in a space other than device memory, the SDK stops on a panic.

Buffers accessed by the GPU may also be allocated from VRAM.

Table 3-2. Buffers That Cannot Be Allocated From Device Memory

Buffer

Comments

Buffer storing microphone sampling results

Must be 4096-byte aligned, and its size must be a multiple of 4096 bytes.

UDS library’s receive buffer

Must be 4096-byte aligned, and its size must be a multiple of 4096 bytes.

Socket library’s receive buffer

Must be 4096-byte aligned, and its size must be a multiple of 4096 bytes.

HTTP library’s working buffer

Must be 4096-byte aligned, and its size must be a multiple of 4096 bytes.

DLP library’s working buffer

Must be 4096-byte aligned, and its size must be a multiple of 4096 bytes.

ACT library communication buffer

Must be 4096-byte aligned, and its size must be a multiple of 4096 bytes.

3.1.3. VRAM

VRAM consists of the two regions VRAM-A and VRAM-B, each 3 MB, for a total of 6 MB.

Applications must manage memory regions used by the GX (graphics) library, such as by allocating color buffers. (Note that when reading VRAM on the CPU, the data is not guaranteed to be accurate.) To allocate memory in VRAM, use the nngxGetVramStartAddr, nngxGetVramEndAddr, and nngxGetVramSize functions to get the start and end addresses and size of VRAM to manage the location of the requested memory regions.

For more information about the GX library and how to manage memory used by libraries, see 5.5. Initializing the GX Library (in this manual) and the 3DS Programming Manual: Basic Graphics.

3.1.4. Heap Memory

This memory is freely usable by applications, such as for allocating file read and write buffers. Use the nn::os::SetHeapSize function to specify the size of heap memory to allocate. On CTR, the total of main program and device memory must be no greater than 64 MB (96 MB for development units). On SNAKE, the heap can use up to 96 MB and the total of main program, heap memory, and device memory must be no greater than 124 MB (178 MB for development hardware). Call this function again to change the size of the memory region to allocate. There is no guarantee that the address of the memory region allocated will be the same for every call. After specifying the size, use the nn::os::GetHeapAddr function to get the starting address of the region. Use the nn::os::GetHeapSize function to get the size of the currently allocated heap.

3.2. Nintendo 3DS Game Cards

There are two types of Nintendo 3DS Game Cards: CARD1 and CARD2. The card most appropriate for use is determined by the game title’s specifications.

Warning:

As a rule, use CARD1 for game titles with a backup memory capacity of 512 KB, and use CARD2 for those with a capacity of 1 MB or more.

3.2.1. CARD1

CARD1 cards come equipped with both read-only memory (ROM) and backup memory (rewritable non-volatile memory).

3.2.1.1. ROM

The CARD1 ROM transfer speed varies depending on the version of the SDK in use and the size of the data being transferred. The actual speed may also vary slightly due to differences in individual cards, so do not design applications that depend on transfer speeds.

There are six different ROM capacities, ranging from 128 MB to 4 GB.

Table 3-3. ROM Capacity (CARD1)

ROM Capacity

Transfer
Speed

Usable Space Size by Market

Japan, North America, Korea

Europe

China, Taiwan

128 MB

(See Note)

93.5 MB
(98,041,856 bytes)

91.5 MB
(95,944,704 bytes)

61.5 MB
(64,487,424 bytes)

256 MB

219.0 MB
(229,638,144 bytes)

217.0 MB
(227,540,992 bytes)

187.0 MB
(196,083,712 bytes)

512 MB

470.0 MB

(492,830,720 bytes)

468.0 MB
(490,733,568 bytes)

438.0 MB
(459,276,288 bytes)

1 GB

921.5 MB
(966,262,784 bytes)

919.5 MB
(964,165,632 bytes)

889.5 MB
(932,708,352 bytes)

2 GB

1875.5 MB
(1,966,604,288 bytes)

1873.5 MB
(1,964,507,136 bytes)

1843.5 MB
(1,933,049,856 bytes)

4 GB

3783.0 MB
(3,966,763,008 bytes)

3781.0 MB
(3,964,665,856 bytes)

3751.0 MB
(3,933,208,576 bytes)

Transfer speeds depend on the version of the SDK and the size of the data. For more information, see 3DS Performance Tips.

3.2.1.2. Backup Memory

The transfer speed for backup memory in CARD1 cards depends on the version of the SDK in use and the size of the data being transferred. The actual speed may also vary slightly due to differences in individual cards, so do not design applications that depend on transfer speeds. See the CTR Guidelines and follow its standards for the number of write operations.

There are two different backup memory capacities, either 128 KB or 512 KB. Use a CARD2 card if you need 1 MB or more of backup memory.

The content of backup memory at time of shipment is guaranteed to be padded with 0xFF throughout the entire memory region, so pad all of the backup memory with 0xFF when emulating the memory state at time of shipment.

You can enable automatic redundancy of the backup memory region used for save data files. However, when automatic redundancy is enabled, the capacity available for saving files is roughly 40% of the total capacity.

Table 3-4. Backup Memory Capacity (CARD1)

Backup Memory Capacity

Transfer Speed

Usable Region Size When Automatic Redundancy Is Enabled

128 KB

(See Note)

50 KB or less

512 KB

239 KB or less

Transfer speeds depend on the version of the SDK and the size of the data. For more information, see 3DS Performance Tips.

3.2.2. CARD2

CARD2 cards come equipped with writable memory that has features of both ROM and backup memory.

3.2.2.1. Writable Memory

The transfer speed for writable memory in CARD2 cards depends on the version of the SDK used and the size of the data involved. The actual speed may vary slightly due to differences in individual cards, so do not design applications that depend on transfer speeds. See the CTR Guidelines and follow its standards for the number of write operations.

With writable memory, you can change the boundaries of the ROM (read-only) and backup (rewritable) regions in 1-MB increments.

You can use the library to enable automatic redundancy for data in backup memory, just as with CARD1 backup memory. Calculate the usable capacity for saving files in a similar manner. The maximum file size that you can specify as backup space is half of the writable memory capacity. There are three sizes of writable memory capacity: 512 MB, 1 GB, and 2 GB.

Table 3-5. Writable Memory Capacity (CARD2)

Writable Memory Capacity

Transfer
Speed

Usable Space Size by Market

Japan, North America, Korea

For Europe

China, Taiwan

512 MB

(See Note)

412.5 MB
(432,537,600 bytes)

410.5 MB
(430,440,448 bytes)

412.5 MB
(432,537,600 bytes)

1 GB

889.5 MB
(932,708,352 bytes)

887.5 MB
(930,61,200 bytes)

889.5 MB
(932,708,352 bytes)

2 GB

1843.5 MB
(1,933,049,856 bytes)

1841.5 MB
(1,930,952,704 bytes)

1843.5 MB
(1,933,049,856 bytes)

Transfer speeds depend on the version of the SDK and the size of the data. For more information, see 3DS Performance Tips.


CONFIDENTIAL