elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Problemas con array muy grande y el Windows7
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Problemas con array muy grande y el Windows7  (Leído 1,478 veces)
OfTheVara

Desconectado Desconectado

Mensajes: 46


Ver Perfil
Problemas con array muy grande y el Windows7
« en: 16 Octubre 2015, 00:59 am »

Hola,

Al iniciar mi programa necesito cargar unos 850.000 bytes contenidos en el archivo "prueba.dat".

Me creo un array adecuado y leo los datos del archivo:

Código:

  Dim VectorBytes(0 To 900000) As Byte
 
  Open App.Path & "\" & "prueba.dat" For Binary Lock Read As 1
    Get #1, , VectorBytes
  Close



Pues en WindowsXP todo correcto. Pero al ejecutarlo en Windows7 se cierra el programa sin decir ni pio, porque no acepta la creacion de un vector de 900.000. Maximo unos 60.000 o menos.

¿Alguien sabe como solucionar esto o que está pasando?
 


« Última modificación: 16 Octubre 2015, 01:02 am por OfTheVara » En línea

Lekim

Desconectado Desconectado

Mensajes: 268



Ver Perfil
Re: Problemas con array muy grande y el Windows7
« Respuesta #1 en: 23 Octubre 2015, 02:08 am »

No tengo Window7, ni siquiera en Virtualbox pero puedo sugerirte varias cosas

Primera:
Si la línea ReDim byte... está desactivada se cargan todos los bytes. Si solo quieres una porción por ejemplo de 500 bytes, activa la línea quitando ' y estableces el ReDim bytes(500).

Código
  1. Dim VectorBytes() As Byte
  2.  
  3.  Open App.Path & "\" & "prueba.dat" For Binary Lock Read As 1
  4. VectorBytes= Space(LOF(1))
  5. ' ReDim bytes(?) '<<--- Forma selectiva de bytes Ej. (500)
  6.    Get #1, , VectorBytes
  7.  Close #1


Segunda
Crear el Array del archivo mediante API

Código
  1. Const FILE_ATTRIBUTE_TEMPORARY = &H100
  2. Const OPEN_EXISTING = 3
  3. Const GENERIC_READ = &H80000000
  4. Const GENERIC_WRITE = &H40000000
  5. Const FILE_ATTRIBUTE_NORMAL = &H80
  6. Const OPEN_ALWAYS = 4
  7. Const INVALID_HANDLE_VALUE = -1
  8.  
  9. Private Declare Function FlushFileBuffers Lib "kernel32" ( _
  10.        ByVal hFile As Long) As Long
  11.  
  12.  
  13. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  14. Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
  15. Private Declare Function SetVolumeLabel Lib "kernel32" Alias "SetVolumeLabelA" _
  16. (ByVal lpRootPathName As String, ByVal lpVolumeName As String) As Long
  17.  
  18. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, _
  19. ByVal dwDesiredAccess As Long, _
  20. ByVal dwShareMode As Long, _
  21. ByVal lpSecurityAttributes As Any, _
  22. ByVal dwCreationDisposition As Long, _
  23. ByVal dwFlagsAndAttributes As Long, _
  24. ByVal hTemplateFile As Long) As Long
  25.  
  26. Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, _
  27. lpBuffer As Any, _
  28. ByVal nNumberOfBytesToRead As Long, _
  29. lpNumberOfBytesRead As Long, _
  30. ByVal lpOverlapped As Any) As Long
  31.  
  32.  
  33. Private Declare Function WriteFile Lib "kernel32" _
  34. (ByVal hFile As Long, lpBuffer As Any, _
  35. ByVal nNumberOfBytesToWrite As Long, _
  36. lpNumberOfBytesWritten As Long, _
  37. ByVal lpOverlapped As Any) As Long
  38.  
  39. Private Sub Command1_Click()
  40.    Dim hFile As Long
  41.    Dim fBytes() As Byte <==Array del archivo
  42.    Dim fSize As Long, lBytesRead As Long
  43.    Dim fSuccess As Long
  44.    Dim BytesToRead As Long
  45.    Dim FileToRead As String
  46.  
  47.   FileToRead = App.Path & "\" & "Prueba.dat"
  48.  
  49.  
  50.    '///LEE EL ARCHIVO EN BYTES ///////////////////
  51.    hFile = CreateFile(FileToRead, _
  52.    GENERIC_WRITE Or GENERIC_READ, 0&, 0&, _
  53.    OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0&)
  54.    If hFile <> INVALID_HANDLE_VALUE Then
  55.    fSize = GetFileSize(hFile, 0)
  56.    ReDim fBytes(fSize)
  57.    BytesToRead = (UBound(fBytes) + 1) * LenB(fBytes(0))
  58.    fSuccess = ReadFile(hFile, fBytes(LBound(fBytes)), BytesToRead, lBytesRead, 0&)
  59.    CloseHandle hFile
  60.     End If
  61.    '/////////////////////////////////////////////
  62.  
  63.  
  64.  
  65. ' Guardar el archivo en otro directorio (Con API)
  66.  Call CrearAchivoBinario("C:\PruebaCopia.dat", fBytes)
  67.  
  68.  
  69.  
  70. '///guardar el archivo en otro directorio (Sin API)
  71.    'Open "C:\PruebaCopia.dat" For Binary Access Write As 1
  72.    'Put #1, , fBytes
  73.    'Close
  74. End Sub
  75.  
  76.  
  77.   Private Sub CrearAchivoBinario(ByVal FileName As String, fBytes() As Byte)
  78.    Dim fSuccess As Long
  79.    Dim hFile As Long
  80.    Dim BytesToRead As Long
  81.    Dim lBytesWritten As Long
  82.  
  83.       BytesToWrite = (UBound(fBytes) + 1) * LenB(fBytes(1))
  84.          hFile = CreateFile(FileName, _
  85.          GENERIC_WRITE Or GENERIC_READ, _
  86.          ByVal 0&, ByVal 0&, _
  87.          OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0&)
  88.  
  89.            If hFile <> INVALID_HANDLE_VALUE Then
  90.          fSuccess = WriteFile(hFile, fBytes(LBound(fBytes)), BytesToWrite, lBytesWritten, 0&)
  91.  
  92.            If fSuccess <> 0 Then
  93.               fSuccess = FlushFileBuffers(hFile)
  94.               fSuccess = CloseHandle(hFile)
  95.            End If
  96.            End If
  97.  
  98.      End Sub
  99.  


He añadido CrearAchivoBinario por si quieres crearlo a partir del array y tuvieras también problemas con eso.

+Info:
https://support.microsoft.com/es-es/kb/165942


« Última modificación: 23 Octubre 2015, 06:17 am por Lekim » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
problemas con array multidimencional
PHP
Zeroql 7 4,031 Último mensaje 1 Julio 2011, 00:03 am
por Zeroql
Problemas con el explorador de Windows7 x64 en portatiles Asus
Windows
D0dg3r 5 4,787 Último mensaje 26 Julio 2012, 15:20 pm
por dato000
[Resuelto] Problemas con un Array
PHP
DeXon18 2 1,775 Último mensaje 3 Junio 2015, 20:22 pm
por DeXon18
¿Hay problemas al cargar pagina grande de ipn?
Programación General
jeber 0 1,528 Último mensaje 26 Septiembre 2015, 10:06 am
por jeber
¿Cómo de grande es Internet? Usuarios, tráfico y problemas futuros
Noticias
wolfbcn 0 1,595 Último mensaje 24 Noviembre 2016, 21:53 pm
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines