/*
 Copyright (c) 2006 Eric J. Feminella  <eric@ericfeminella.com>
 All rights reserved.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is furnished
 to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all
 copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 @internal
 */

package com.ericfeminella.diagnostics
{
    /**
     *
     * Creates a snap shot of the total allocated memory used
     * by Flash Player which is used for diagnostic purposes.
     *
     * @example The following example demonstrates how to create
     * a MemorySnapshot at a specific point in time
     *
     * <listing version="3.0">
     *
     * var ms:MemorySnapshot = new MemorySnapshot();
     * // execute additional code...
     *
     * trace( ms.memoryAtSnapshot );
     * trace( ms.timeOfSnapshot );
     *
     * </listing>
     *
     */
    public final class MemorySnapshot
    {
        /**
         *
         * @private
         *
         * Defines the total memory allocated by Flash Player
         * at the time of the memory snap shot.
         *
         */
        private var memory:Number;

        /**
         *
         * @private
         *
         * Defines the <code>Date</code> in which the memory snap
         * shot was taken.
         *
         */
        private var timestamp:Date;

        /**
         *
         * <code>MemorySnapShot</code> constructor takes a snap shot
         * of the current memory allocated to Flash Player.
         *
         */
        public function MemorySnapshot()
        {
            this.memory = SystemDiagnostics.allocatedMemory();
            this.timestamp = new Date();
        }

        /**
         *
         * Retrieves the total memory allocated by Flash Player
         * at the time of the memory snap shot.
         *
         * @return memory used by Flash Player at time of snapshot
         *
         */
        public function get memoryAtSnapshot() : Number
        {
            return memory;
        }

        /**
         *
         * Retrieves the Date in which the memory snap
         * shot was taken.
         *
         * @return exact time the snap shot was taken
         *
         */
        public function get timeOfSnapshot() : Date
        {
            return timestamp;
        }
    }
}