Search found 33 matches

by SnowyDog
Fri Jul 25, 2025 12:25 pm
Forum: Coding Questions
Topic: Memory (re)allocation / structure pointer initialisation safety
Replies: 3
Views: 196

Re: Memory (re)allocation / structure pointer initialisation safety

Yes, the pointer will remain valid. They are basically just numbers.
Do you mean the pointer itself or the allocated memory block it references will remain valid?
by SnowyDog
Fri Jul 25, 2025 10:50 am
Forum: Coding Questions
Topic: Memory (re)allocation / structure pointer initialisation safety
Replies: 3
Views: 196

Memory (re)allocation / structure pointer initialisation safety

In this code I am initialising a memory pointer and a pointer to a structure in a sub function for use outside the sub function. It compiles and works, but is it safe - i.e. will the pointers always stay valid outside the sub function?

I was particularly surprised that ReAllocateMemory() accepts a ...
by SnowyDog
Tue Apr 08, 2025 1:22 pm
Forum: Coding Questions
Topic: Memory reallocation within a sub function...
Replies: 18
Views: 991

Re: Memory reallocation within a sub function...

Thanks again for your time, Demivec. I'm sure this info will be helpful to others too.
by SnowyDog
Mon Apr 07, 2025 9:46 am
Forum: Coding Questions
Topic: Memory reallocation within a sub function...
Replies: 18
Views: 991

Re: Memory reallocation within a sub function...

Demivec, this is incredibly helpful. Thank you for taking the time to post this.

I think my initial misunderstanding stems from the fact that in PB, "*" is not treated as an indirection operator as it is in C. Because, if it is, then @*MemPtr makes no sense as you would be dereferencing the pointer ...
by SnowyDog
Sun Apr 06, 2025 7:23 pm
Forum: Coding Questions
Topic: Memory reallocation within a sub function...
Replies: 18
Views: 991

Re: Memory reallocation within a sub function...


Where should I be looking (in available documentation) to find this information, please?
Have you tried opening Tools-Structure Viewer[Alt+s]?


Thanks, yes - I see the built-in structures there which is great - now I know I need to use one to pass a pointer by reference to a procedure.

But ...
by SnowyDog
Sun Apr 06, 2025 4:08 pm
Forum: Coding Questions
Topic: Memory reallocation within a sub function...
Replies: 18
Views: 991

Re: Memory reallocation within a sub function...


You can't have a pointer to a stack-allocated type, because for some reason even though C can do it PB refuses. So, in order to have a pointer to an integer, long, etc., you have to use those structures you found. Don't feel bad, this is woefully confusing and rather annoying, I wish PB would just ...
by SnowyDog
Sun Apr 06, 2025 3:16 pm
Forum: Coding Questions
Topic: Memory reallocation within a sub function...
Replies: 18
Views: 991

Re: Memory reallocation within a sub function...

I just want to understand how I have managed to misunderstand this fundamental concept! I have been using PB for some time and this is the first time I've run into this.

It seems to me that there is nothing in the PB help or online docs that indicates that a pointer can't simply be passed by ...
by SnowyDog
Sun Apr 06, 2025 2:24 pm
Forum: Coding Questions
Topic: Memory reallocation within a sub function...
Replies: 18
Views: 991

Re: Memory reallocation within a sub function...

Thanks for your replies.

In your example, mk-soft, you are assigning the .integer structure to the pointer - something that I wasn't even aware was possible.

I thought it was only possible to assign the built-in data types to a variable using the single-letter suffix (e.g. myvar.i) but of course ...
by SnowyDog
Sat Apr 05, 2025 9:27 pm
Forum: Coding Questions
Topic: Check progress of WriteSerialPortData()
Replies: 1
Views: 128

Re: Check progress of WriteSerialPortData()

Hello, I think you can use Result = AvailableSerialPortOutput(#SerialPort) to find out how many bytes remain in the serial output buffer.

A slightly better approach would be to use handshaking (either hardware or software) assuming that the old computer can support either.
by SnowyDog
Sat Apr 05, 2025 9:12 pm
Forum: Coding Questions
Topic: Memory reallocation within a sub function...
Replies: 18
Views: 991

Memory reallocation within a sub function...

Using 6.20 x64

Passing a pointer to an allocated memory block to a sub function which reallocates that memory block to a larger size fails when the memory pointer is passed directly as a parameter. The pointer becomes invalid with error "the specified 'MemoryID' is not valid".

This however ...
by SnowyDog
Fri Nov 15, 2024 4:22 pm
Forum: Windows
Topic: Threads pause during DeviceIoControl()
Replies: 3
Views: 3140

Re: Threads pause during DeviceIoControl()

No, I wouldn't expect this behavior from windows, but I would expect it from badly/incorrectly written programs. No offense.

Thanks for your reply, and no offence taken. Without knowing for sure the cause, I cannot rule this out myself, hence my question.

I would provide example code, but ...
by SnowyDog
Wed Nov 13, 2024 7:21 am
Forum: Windows
Topic: Threads pause during DeviceIoControl()
Replies: 3
Views: 3140

Threads pause during DeviceIoControl()

My GUI application works with SCSI devices using SCSI passthrough (SPTI) in non-overlapped mode, i.e. the call looks like this:

; Make the call
lResult=DeviceIoControl_(*SCSI\hDevice, ; handle to the SPTI device
#IOCTL_SCSI_PASS_THROUGH_DIRECT, ; [in] dwControlCode
*SCSI\SPTDWS\SPTD, ; [in ...
by SnowyDog
Wed Feb 21, 2024 10:12 am
Forum: Coding Questions
Topic: Windows console applications - console mode selection?
Replies: 0
Views: 379

Windows console applications - console mode selection?

Hello all,

I have a collection of PureBasic Windows console mode applications. They are written to exploit "new" console features and although of course will work in legacy console mode, display better out of legacy console mode.

Some of the Windows machines I'm targeting have the legacy console ...
by SnowyDog
Mon Sep 19, 2022 7:03 pm
Forum: The PureBasic Editor
Topic: Retain source file tab order in IDE?
Replies: 2
Views: 1522

Re: Retain source file tab order in IDE?

This is great news, thanks kenmo.
by SnowyDog
Sat Sep 17, 2022 8:44 pm
Forum: The PureBasic Editor
Topic: Retain source file tab order in IDE?
Replies: 2
Views: 1522

Retain source file tab order in IDE?

I have searched the forum but failed to find an answer to this.

When working on a project with multiple source / include files open as tabs across the top of the IDE window, it is possible to change the order in which the file appear left to right, but is there a way to permanently fix this order ...