Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.stansassets.foundation

Package Overview
Dependencies
Maintainers
4
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.stansassets.foundation - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

.github/.kodiak.toml

7

package.json
{
"name": "com.stansassets.foundation",
"displayName": "Stans Assets - Foundation Lib",
"version": "1.0.2",
"displayName": "Stans Assets - Foundation",
"version": "1.0.3",
"unity": "2019.3",

@@ -15,3 +15,4 @@ "description": "Foundation package is a collection of utility methods, design patterns, and extensions for Unity.",

"bugs": {
"url": "https://github.com/StansAssets/com.stansassets.foundation/issues"
"url": "https://github.com/StansAssets/com.stansassets.foundation/issues",
"email" : "support@stansassets.com"
},

@@ -18,0 +19,0 @@ "repository": {

@@ -5,4 +5,6 @@ # Foundation Library

[![NPM Package](https://img.shields.io/npm/v/com.stansassets.foundation)](https://www.npmjs.com/package/com.stansassets.foundation)
[![openupm](https://img.shields.io/npm/v/com.stansassets.foundation?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.stansassets.foundation/)
[![Licence](https://img.shields.io/npm/l/com.stansassets.foundation)](https://github.com/StansAssets/com.stansassets.foundation/blob/master/LICENSE)
[![Issues](https://img.shields.io/github/issues/StansAssets/com.stansassets.foundation)](https://github.com/StansAssets/com.stansassets.foundation/issues)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a22ff0164da04d089f68d8209dbe6c10)](https://app.codacy.com/gh/StansAssets/com.stansassets.foundation?utm_source=github.com&utm_medium=referral&utm_content=StansAssets/com.stansassets.foundation&utm_campaign=Badge_Grade_Dashboard)

@@ -19,3 +21,3 @@

### Recommended way to install
### Install from NPM
* Navigate to the `Packages` directory of your project.

@@ -35,3 +37,3 @@ * Adjust the [project manifest file](https://docs.unity3d.com/Manual/upm-manifestPrj.html) `manifest.json` in a text editor.

"scopes": [
"com.stansasset"
"com.stansassets"
]

@@ -48,5 +50,11 @@ }

### Fast way to install
Yoy can also install this package a Git URL. To load a package from a Git URL:
### Install from OpenUPM
* Install openupm-cli `npm install -g openupm-cli` or `yarn global add openupm-cli`
* Enter your unity project folder `cd <YOUR_UNITY_PROJECT_FOLDER>`
* Install package `openupm add com.stansassets.foundation`
### Install from a Git URL
Yoy can also install this package via Git URL. To load a package from a Git URL:
* Open [Unity Package Manager](https://docs.unity3d.com/Manual/upm-ui.html) window.
* Click the add **+** button in the status bar.

@@ -53,0 +61,0 @@ * The options for adding packages appear.

@@ -1,100 +0,3 @@

# Pooling Pattern
This article demonstrates how to use pool pattern and how useful it could be. If you have ever written a poolable MTS/COM+ component, you can skip this funny intro. Otherwise keep reading... What is a pool? A container, full with water, where fish swim. In our case, an object pool is a container, where objects "swim" :) No, seriously, the object pool is a container, which not only allows objects to be drawn from, and returned back, but also creates them on the fly, whenever you want to draw more objects than you have at hand. When you need a new object, the pool searches for a free object to give you. If the "fish" is not found in the pool, the pool "gives birth" to a bunch of brand new objects and hands you one of them. If a free one was found, the pool just gives it to you. "But why", you'll wonder, "do I need an object pool that creates objects? Can't I just instantiate as many objects as I wish?". My answer is: Yes, you could. But not in all cases. There are some special cases, where to just pull the caught fish from the bucket is better (and definitely faster) then to catch a new fish.
# Pooling Pattern
Read full pooling pattern guide [here](https://github.com/StansAssets/com.stansassets.foundation/wiki/Pooling-Pattern).
## Reusing objects (not classes)
If all objects were small and fast, the programmer would die from happiness, that's why the world serves us heavy tasks which need heavy objects. And heavy not only means that an object has many data embedded in properties and data structures but also means heavy initialization code. Imagine you have a bunch of Dictionary objects, which are essentially the same but are used to translate different languages. Well, they could easily be written as a single class, which takes an argument -- the desired language. The object then, connects to a database, pulls N megabytes, stores it in some internal data structures, and is ready to be used. Now imagine that you should create a new object for every instance of its client. Well, I guess you don't want to waste a minute or so for each Dictionary creation, do you? So the problem is apparent, but the solution not yet. If there were some mechanism which allowed you to create the objects, store them anywhere, put them to sleep, and wake them only when you need them, you wouldn't have any problem, right? (Maybe.:) Right! Here's were object (not class) reuse come to help you. I've seen several implementations of object pooling, of which the best one is Microsoft's implementation of COM+ components pooling. I'll not compete with Microsoft (yet:), but will give the first (known to me) implementation of object pooling for .NET objects. So read along and enjoy...
## History (or about COM+ pooling)
(This subsection's text is copy/pasted from Platform SDK/Component Services/ Services Provided by COM+/Object Pooling and is copyrighted (c) material of Microsoft corp.)
Object pooling is an automatic service provided by COM+ that enables you to configure a component to have instances of itself kept active in a pool, ready to be used by any client that requests the component. You can administratively configure and monitor the pool maintained for a given component, specifying characteristics such as pool size and creation request time-out values. When the application is running, COM+ manages the pool for you, handling the details of object activation and reuse according to the criteria you have specified.
You can achieve very significant performance and scaling benefits by reusing objects in this manner, particularly when they are written to take full advantage of reuse. With object pooling, you gain the following benefits:
* You can speed object use time for each client, factoring out time-consuming initialization and resource acquisition from the actual work that the object performs for clients.
* You can share the cost of acquiring expensive resources across all clients.
* You can pre-allocate objects when the application starts, before any client requests come in.
* You can govern resource use with administrative pool management—for example, by setting an appropriate maximum pool level, you can keep open only as many database connections as you have a license for.
* You can administratively configure pooling to take the best advantage of available hardware resources—you can easily adjust the pool configuration as available hardware resources change.
* You can speed reactivation time for objects that use Just-in-Time (JIT) activation, while deliberately controlling how resources are dedicated to clients.
## Pooling with ObjectPool
* speed object use time...
* share the cost of acquiring expensive resources...
* pre-allocate objects when the application starts...
* construct (configure) objects, like COM+ (not mentioned above)
### Default pool
The default pool implementation is used for the most common and simple poll use cases.
```csharp
public class TestClassObject
{
public int IntValue;
public string StringValue;
}
var pool = new DefaultPool<TestClassObject>();
var testClassObject = pool.Get();
// Do something
pool.Release(testClassObject);
```
using via `PooledObject`
```csharp
using (pool.Get(out var testClassObject2))
{
// Do something
}
```
### Collection Pool
The collection is designed to reuse collection instances across the project. So instead:
```csharp
var myList = new List<string>();
```
you may use:
```csharp
var myList = ListPool<string>.Get();
// Do something
ListPool<string>.Release(myList);
```
or
```csharp
using (ListPool<string>.Get(out var myList))
{
// Do something
}
```
### Prefabs Spawn
Spawning prefabs is the most common Unity use case. The code snippet below will demonstrate how to implement it using `ObjectPool`.
Without a pool, your code would look similar to:
```csharp
GameObject prefabLink = null;
var instance = Object.Instantiate(prefabLink);
instance.SetActive(true);
// Do something
Object.Destroy(instance);
```
Same implementation but with `ObjectPool`.
```csharp
// Pool setup.
var prefabsPool = new ObjectPool<GameObject>(
() => Object.Instantiate(prefabLink),
(prefab) => prefab.SetActive(true),
(prefab) => prefab.SetActive(false));
// spawn
var instance = prefabsPool.Get();
// Do something
prefabsPool.Release(instance);
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc