# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ret2basic.gitbook.io/ctfwriteup/web2-ctf/pwn.college/dynamic-allocator-misuse/tcache.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
