Skip to content

Avoid Marshal.PtrToStructure in NativeWrapper #118996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

xtqqczze
Copy link
Contributor

@xtqqczze xtqqczze commented Aug 22, 2025

Avoids an unnecessary cast to long on 32-bit systems, which could introduce inefficiency without providing any benefit.

Best reviewed hiding whitespace changes.

Avoids an unnecessary cast to long on 32-bit systems, which could introduce
inefficiency without providing any benefit.
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 22, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Aug 22, 2025
@jkotas jkotas added area-System.Diagnostics.EventLog and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Aug 22, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-diagnostics-eventlog
See info in area-owners.md if you want to be subscribed.

@xtqqczze xtqqczze changed the title Simplify pointer arithmetic in NativeWrapper Avoid Marshal.PtrToStructure in NativeWrapper Aug 22, 2025
{
bool status = UnsafeNativeMethods.EvtRender(contextHandle, eventHandle, flag, 0, IntPtr.Zero, out bufferNeeded, out propCount);
bool status = UnsafeNativeMethods.EvtRender(contextHandle, eventHandle, flag, 0, (UnsafeNativeMethods.EvtVariant*)null, out int bufferNeeded, out int propCount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool status = UnsafeNativeMethods.EvtRender(contextHandle, eventHandle, flag, 0, (UnsafeNativeMethods.EvtVariant*)null, out int bufferNeeded, out int propCount);
bool status = UnsafeNativeMethods.EvtRender(contextHandle, eventHandle, flag, 0, null, out int bufferNeeded, out int propCount);

Why do we need to cast here? Many other places pass in null just fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I see there is an ambiguous overload. There seem to be more places that have the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Diagnostics.EventLog community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants