> For the complete documentation index, see [llms.txt](https://ret2basic.gitbook.io/ctfwriteup/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ret2basic.gitbook.io/ctfwriteup/web2-ctf/pwn.college/dynamic-allocator-misuse/tcache.md).

# tcache

## Lecture

{% embed url="<https://youtu.be/0jHtqqdVv1Y>" %}
tcache
{% endembed %}

## tcache

**Thread Local Caching (tcache)** in ptmalloc speeds up repeated (small) allocations in a single thread. It is implemented as a **singly-linked list**, with each thread having a list header for different-sized allocations:

```c
typedef struct tcache_perthread_struct
{
  char counts[TCACHE_MAX_BINS];
  tcache_entry *entries[TCACHE_MAX_BINS];
} tcache_perthread_struct;

typedef struct tcache_entry
{
  struct tcache_entry *next;
  struct tcache_perthread_struct *key;
} tcache_entry;
```

## How did we get here?

Watch the lecture.
