Memory.cs
Description du code
Memory.cs est un fichier du projet BiblioBrol.Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/src/.
Projet BiblioBrol :
Gestion de media en CSharp.
Pour plus d'infos, vous pouvez consulter la brève analyse.
Code source ou contenu du fichier
Code c# (Memory.cs) (136 lignes)
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.ComponentModel; using be.gaudry.bibliobrol.config; namespace be.gaudry.bibliobrol.model.eid { public class Memory { #region Enumerations public enum AllocationFlags : int { Fixed = 0, Movable = 2, ZeroInit = 0x40, FixedZeroInit = (Fixed + ZeroInit) } #endregion #region Imports [DllImport(Config.Kernel32DLL, SetLastError = true)] private static extern IntPtr LocalAlloc(AllocationFlags flags, int bytes); [DllImport(Config.Kernel32DLL, SetLastError = true)] private static extern IntPtr LocalFree(IntPtr handle); [DllImport(Config.Kernel32DLL, SetLastError = true)] private static extern IntPtr LocalReAlloc(IntPtr handle, int bytes, AllocationFlags flags); #endregion #region Methods // Allocates a block of memory using LocalAlloc public static IntPtr AllocHLocal(int cb) { // allocate and return return LocalAlloc(AllocationFlags.FixedZeroInit, cb); } // Frees memory allocated by AllocHLocal public static void FreeHLocal(IntPtr handle) { // check if zero if (!handle.Equals(IntPtr.Zero)) { // free it first if (!IntPtr.Zero.Equals(LocalFree(handle))) { // throw exception } else { // clear handle = IntPtr.Zero; } } } // Resizes a block of memory previously allocated with AllocHLocal public static IntPtr ReAllocHLocal(IntPtr pv, int cb) { // allocate IntPtr newMem = LocalReAlloc(pv, cb, AllocationFlags.Movable); // check if (newMem.Equals(IntPtr.Zero)) { // something went wrong } // return allocated handle return newMem; } // Copies the contents of a managed string to unmanaged memory public static IntPtr StringToHLocalUni(string s) { // check if zero if (s == null) { // retrurn empty return IntPtr.Zero; } else { // get length int nc = s.Length; int length = 2 * (1 + nc); // allocate proper length IntPtr handle = AllocHLocal(length); // check if successfull if (handle.Equals(IntPtr.Zero)) { // something went wrong } else { // copy Marshal.Copy(s.ToCharArray(), 0, handle, s.Length); // return new handle return handle; } } } // Copies the contents of a managed string to unmanaged memory public static IntPtr ByteToHLocal(byte[] data, int offset, int count) { // check if zero if (data == null) { // retrurn empty return IntPtr.Zero; } else { // allocate proper length IntPtr handle = AllocHLocal(count); // check if successfull if (handle.Equals(IntPtr.Zero)) { // something went wrong } else { // copy Marshal.Copy(data, offset, handle, count); // return new handle return handle; } } } #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1738478632 02/02/2025 07:43:52 |
Utilisation de l'explorateur de code
- Navigation :
- Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
- Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
- La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
- Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
- Affichage :
- Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
- Actions :
- Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 16/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-bibliobrol-source-rf-model/eid/Memory.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.