<commit_before>---
title: "Data Transmission with Delphi (Part 1: Pointers and Structures)"
excerpt_separator: "<!--more-->"
categories:
  - Data Transmission
tags:
  - Delphi  
  - Communication
  - Cross-Language
  - DLL
  - Records
  - Structs

---

In this blog post I will start to describe the data structures and the use of pointers in communicating cross-platform via DLLs. 

<!--more-->
The purpose of this blog series is to understand how to transfer raw data at high speed with direct access using pointers to structures that can be supported by most programming platforms.

When we transmit data between an application and a DLL, we operate in the same memory space. This means that we can read memory directly via pointers. This allows high speed transmission of data by directly reading memory as common structures shared between the application and DLLs. 

## Pointer Primer ##

Many tutorials on pointers exist already and this is not a replacement for those, just a basic primer and refresher on high level concepts. 

Think of memory as a grid of boxes where each box has a sequential identifier (or address). If we have a memory position in this grid as well as knowledge about the number of boxes to read beyond that position, and their interpretation, then two systems with this common understanding can create an efficient system of directly sharing information.

In the model described above a pointer is simply the address of a box as described above. I like to think of pointers as "native unsigned integers". Thinking about pointers this way helps keep our sanity when passing pointers by value or by reference. The value held by the pointer behaves in the same way as a numeric value passed by value or by reference. 

Let us look at a sample of a pointer type defined in System.SysUtils.pas

{% highlight pascal %}
PThreadInfo = ^TThreadInfo;
TThreadInfo = record
  Next: PThreadInfo;<commit_msg>Add sidebar<commit_after>---
title: "Data Transmission with Delphi (Part 1: Pointers and Structures)"
excerpt_separator: "<!--more-->"
categories:
  - Data Transmission
tags:
  - Delphi  
  - Communication
  - Cross-Language
  - DLL
  - Records
  - Structs
sidebar:
  nav: data_transmission
---

In this blog post I will start to describe the data structures and the use of pointers in communicating cross-platform via DLLs. 

<!--more-->
The purpose of this blog series is to understand how to transfer raw data at high speed with direct access using pointers to structures that can be supported by most programming platforms.

When we transmit data between an application and a DLL, we operate in the same memory space. This means that we can read memory directly via pointers. This allows high speed transmission of data by directly reading memory as common structures shared between the application and DLLs. 

## Pointer Primer ##

Many tutorials on pointers exist already and this is not a replacement for those, just a basic primer and refresher on high level concepts. 

Think of memory as a grid of boxes where each box has a sequential identifier (or address). If we have a memory position in this grid as well as knowledge about the number of boxes to read beyond that position, and their interpretation, then two systems with this common understanding can create an efficient system of directly sharing information.

In the model described above a pointer is simply the address of a box as described above. I like to think of pointers as "native unsigned integers". Thinking about pointers this way helps keep our sanity when passing pointers by value or by reference. The value held by the pointer behaves in the same way as a numeric value passed by value or by reference. 

Let us look at a sample of a pointer type defined in System.SysUtils.pas

{% highlight pascal %}
PThreadInfo = ^TThreadInfo;
TThreadInfo = record
  Next: PThreadInfo;
{'fraction_non_alphanumeric': 0.041247744263985565, 'fraction_numerical': 0.0005155968032998196, 'mean_word_length': 4.091863517060368, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5510557', 'n_tokens_mistral': 935, 'n_tokens_neox': 864, 'n_words': 595}