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

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Runtime.InteropServices;
  5. using System.ComponentModel;
  6. using be.gaudry.bibliobrol.config;
  7.  
  8. namespace be.gaudry.bibliobrol.model.eid
  9. {
  10. public class Memory
  11. {
  12. #region Enumerations
  13. public enum AllocationFlags : int
  14. {
  15. Fixed = 0,
  16. Movable = 2,
  17. ZeroInit = 0x40,
  18. FixedZeroInit = (Fixed + ZeroInit)
  19. }
  20. #endregion
  21.  
  22. #region Imports
  23. [DllImport(Config.Kernel32DLL, SetLastError = true)]
  24. private static extern IntPtr LocalAlloc(AllocationFlags flags, int bytes);
  25.  
  26. [DllImport(Config.Kernel32DLL, SetLastError = true)]
  27. private static extern IntPtr LocalFree(IntPtr handle);
  28.  
  29. [DllImport(Config.Kernel32DLL, SetLastError = true)]
  30. private static extern IntPtr LocalReAlloc(IntPtr handle, int bytes,
  31. AllocationFlags flags);
  32. #endregion
  33.  
  34. #region Methods
  35. // Allocates a block of memory using LocalAlloc
  36. public static IntPtr AllocHLocal(int cb)
  37. {
  38. // allocate and return
  39. return LocalAlloc(AllocationFlags.FixedZeroInit, cb);
  40. }
  41.  
  42. // Frees memory allocated by AllocHLocal
  43. public static void FreeHLocal(IntPtr handle)
  44. {
  45. // check if zero
  46. if (!handle.Equals(IntPtr.Zero))
  47. {
  48. // free it first
  49. if (!IntPtr.Zero.Equals(LocalFree(handle)))
  50. {
  51. // throw exception
  52. throw new Win32Exception(Marshal.GetLastWin32Error());
  53. }
  54. else
  55. {
  56. // clear
  57. handle = IntPtr.Zero;
  58. }
  59. }
  60. }
  61. // Resizes a block of memory previously allocated with AllocHLocal
  62. public static IntPtr ReAllocHLocal(IntPtr pv, int cb)
  63. {
  64. // allocate
  65. IntPtr newMem = LocalReAlloc(pv, cb, AllocationFlags.Movable);
  66. // check
  67. if (newMem.Equals(IntPtr.Zero))
  68. {
  69. // something went wrong
  70. throw new OutOfMemoryException();
  71. }
  72. // return allocated handle
  73. return newMem;
  74. }
  75. // Copies the contents of a managed string to unmanaged memory
  76. public static IntPtr StringToHLocalUni(string s)
  77. {
  78. // check if zero
  79. if (s == null)
  80. {
  81. // retrurn empty
  82. return IntPtr.Zero;
  83. }
  84. else
  85. {
  86. // get length
  87. int nc = s.Length;
  88. int length = 2 * (1 + nc);
  89. // allocate proper length
  90. IntPtr handle = AllocHLocal(length);
  91. // check if successfull
  92. if (handle.Equals(IntPtr.Zero))
  93. {
  94. // something went wrong
  95. throw new OutOfMemoryException();
  96. }
  97. else
  98. {
  99. // copy
  100. Marshal.Copy(s.ToCharArray(), 0, handle, s.Length);
  101. // return new handle
  102. return handle;
  103. }
  104. }
  105. }
  106. // Copies the contents of a managed string to unmanaged memory
  107. public static IntPtr ByteToHLocal(byte[] data, int offset, int count)
  108. {
  109. // check if zero
  110. if (data == null)
  111. {
  112. // retrurn empty
  113. return IntPtr.Zero;
  114. }
  115. else
  116. {
  117. // allocate proper length
  118. IntPtr handle = AllocHLocal(count);
  119. // check if successfull
  120. if (handle.Equals(IntPtr.Zero))
  121. {
  122. // something went wrong
  123. throw new OutOfMemoryException();
  124. }
  125. else
  126. {
  127. // copy
  128. Marshal.Copy(data, offset, handle, count);
  129. // return new handle
  130. return handle;
  131. }
  132. }
  133. }
  134. #endregion
  135. }
  136. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/src/model/eid/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1719383205 26/06/2024 08:26:45
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/src/model/eid/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csEidAdapter.cs27.46 Ko31/10/2018 18:32:54-refusé-
Afficher le fichier .cs|.csMemory.cs4.31 Ko31/10/2018 18:32:54-refusé-
Afficher le fichier .cs|.csBytePtr.cs3.12 Ko31/10/2018 18:32:54-refusé-
Afficher le fichier .cs|.csStringPtr.cs1.81 Ko31/10/2018 18:32:55-refusé-
Afficher le fichier .cs|.csEidPerson.cs171 octets31/10/2018 18:32:54-refusé-

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.

Document créé le 16/10/2009, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/cs-bibliobrol-source-rf-model/eid//Memory.cs.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.