It is currently Sun Dec 16, 2018 6:25 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: ReallocateMemory
PostPosted: Thu Nov 15, 2018 9:45 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Dec 31, 2014 5:41 pm
Posts: 111
In the manual for ReallocateMemory it says;
Code:
*MemoryID The address of the memory area to resize. This value must be the result of a call to AllocateMemory() or ReAllocateMemory().

If this parameter is #Null, the command acts like AllocateMemory() and allocates a new memory area of the given size.

In my code it has this;
Code:
         *DataBuffer = #Null
         For x = 1 To TotalSkillsCounted
            y = x - 1
            TextLength = Len(weaponskillsEx(y)\Language[LanguageCount])
            *NewBuffer = ReAllocateMemory(*DataBuffer, MemorySize(*DataBuffer) + SizeOf(unicode) + TextLength)
            If *NewBuffer
               PokeU(*NewBuffer + WriteOffset,TextLength)
               WriteOffset + #UnicodeLength
               PokeS(*NewBuffer + WriteOffset, weaponskillsEx(y)\Language[LanguageCount], TextLength, #PB_Unicode | #PB_String_NoZero)
               WriteOffset + TextLength
               *DataBuffer = *NewBuffer
            Else
               FreeMemory(*Databuffer)
               ProcedureReturn #AllocateMemoryError
            EndIf
         Next x



And I get this error message
[ERROR] The specified '*MemoryID' is null.

Why is this not legal? *Datapointer is set to 0. (#NULL). Since its 0, it should just allocate memory, rather than reallocate


Top
 Profile  
Reply with quote  
 Post subject: Re: ReallocateMemory
PostPosted: Thu Nov 15, 2018 9:51 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4051
Location: Germany
The address needs to be #Null :!:

If you use a variable *DataBuffer this variable has an address <> #Null.

And ...
please provide always a working code :wink:

Use
Code:
*DataBuffer = AllocateMemory(1)
instead.


Last edited by infratec on Thu Nov 15, 2018 9:54 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ReallocateMemory
PostPosted: Thu Nov 15, 2018 9:53 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Dec 31, 2014 5:41 pm
Posts: 111
I was afraid of that, but hoped I was wrong. That reallocate would allocate rather than reallocate when provided address is 0.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReallocateMemory
PostPosted: Thu Nov 15, 2018 9:55 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4051
Location: Germany
See my 'simple' solution above.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReallocateMemory
PostPosted: Thu Nov 15, 2018 10:08 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 1169
Location: Germany, Glienicke
The error comes from MemorySize(*DataBuffer), because *DataBuffer = #Null!

Code:
*DataBuffer = #Null
ReAllocateMemory(*DataBuffer, 100)

is fine.

_________________
ImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: ReallocateMemory
PostPosted: Thu Nov 15, 2018 10:40 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Dec 31, 2014 5:41 pm
Posts: 111
Doh.. I forgot about that one.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: DarkDragon, Kwai chang caine and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye