# DownloadHandlerScript

> Create a DownloadHandlerScript which allocates new buffers when passing data to callbacks.

## Definition

* **Type:** Constructor
* **Namespace:** [UnityEngine.Networking](/engine/6000.5/script-reference/unityengine/networking.md)
* **Assembly:** UnityEngine.UnityWebRequestModule

## DownloadHandlerScript()

Create a DownloadHandlerScript which allocates new buffers when passing data to callbacks.

```csharp
public DownloadHandlerScript()
```

### Remarks

This default constructor places this DownloadHanderScript into *non-preallocated mode*. This affects the operation of the ReceiveData callback.

When in non-preallocated mode, a new managed byte array will be allocated each time ReceiveData is called, and the length of the array passed to ReceiveData will always be equal to the number of new bytes available for consumption.

This is convenient, but may cause undesirable garbage collection. If your use case requires an implementation which avoids unnecessary garbage collection, use preallocated mode instead.

## DownloadHandlerScript(byte\[])

Create a DownloadHandlerScript which reuses a preallocated buffer to pass data to callbacks.

```csharp
public DownloadHandlerScript(byte[] preallocatedBuffer)
```

### Parameters

**** (\[byte\[]]\(https\://learn.microsoft.com/dotnet/api/system.byte)): A byte buffer into which data will be copied, for use by [DownloadHandler.ReceiveData](/engine/6000.5/script-reference/unityengine/networking/downloadhandler/receivedata.md).

### Remarks

This constructor places this [DownloadHandlerScript](/engine/6000.5/script-reference/unityengine/networking/downloadhandlerscript.md) into *preallocated mode*. This affects the operation of the [DownloadHandler.ReceiveData](/engine/6000.5/script-reference/unityengine/networking/downloadhandler/receivedata.md) callback.

When in preallocated mode, the `preallocatedBuffer` byte array will be repeatedly reused to pass data to the [DownloadHandler.ReceiveData](/engine/6000.5/script-reference/unityengine/networking/downloadhandler/receivedata.md) callback, instead of allocating new buffers each time. The system will not zero-out the array between uses, so the `dataLength` argument to [DownloadHandler.ReceiveData](/engine/6000.5/script-reference/unityengine/networking/downloadhandler/receivedata.md) must be used to discover which bytes are new.

When in this mode, the [DownloadHandlerScript](/engine/6000.5/script-reference/unityengine/networking/downloadhandlerscript.md) will not allocate any memory during the download or processing of HTTP response data. If your use case is sensitive to garbage collection, usage of preallocated mode is recommended.
