# PVK_AllocEnv( ): Allocate Environment

> Source: https://manual.pvxplus.com/c-library-file-io-routines/file-io-routines/allocenv

## Format

**HPVKENV PVK_AllocEnv( );**

***Where:***

|  |  |
| --- | --- |
| **HPVKENV** | Handle to the environment structure, 4-byte value. Returns null on failure. |

## Description

**PVK_AllocEnv( )** is used to allocate the environment. The environment handle must be passed to the following functions to provide thread safety of PXPIO operations: **[PVK_RegisterKey( )](https://manual.pvxplus.com/c-library-file-io-routines/file-io-routines/registerkey)**, **[PVK_OpenExt( )](https://manual.pvxplus.com/c-library-file-io-routines/file-io-routines/openext)**, **[PVSetEnvMode( )](https://manual.pvxplus.com/c-library-file-io-routines/file-io-routines/setenvmode)** and **[PVGetEnvMode( )](https://manual.pvxplus.com/c-library-file-io-routines/file-io-routines/getenvmode)**. The environment handle must be freed at the end of the session to avoid resource leaks.

Warning!  
Attempting to pass a bad or invalid environment handle to any PXPIO function can cause unpredictable results that may lead to abnormal termination.
