Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7976259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:52:20+00:00 2026-06-04T08:52:20+00:00

So I am trying to dynamically allocate a buffer on module initialization. The buffer

  • 0

So I am trying to dynamically allocate a buffer on module initialization. The buffer needs to be in scope at all times as it stores data that user space programs interact with. So here is my code:

static char* file_data
#define MAX_SIZE 256
.
.
.
{
   file_data = kzalloc(MAX_SIZE, GFP_KERNEL)

.
.
.
}

However when I do sizeof file_data it always returns 4. What am I doing wrong?

Edit: The buffer stores input from a user space program, but 4 characters is all that can be stored.

size_t read_file(char* __user buf, size_t count)
{
    unsigned int len = 0;
    len = copy_to_user(buf, file_data, count);
    return count;
}

ssize_t write_file(char* __user buf, size_t count)
{
    if(count >= MAX_SIZE)
        return -EINVAL;
    copy_from_user(file_data, buf,count)
    return count;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:52:21+00:00Added an answer on June 4, 2026 at 8:52 am

    file_data is a pointer. On a 32-bit platform, it’s size is 32 bits, or 4 bytes. What you want to know is the size of the data pointed to by file_data. You can’t use the sizeof operator for this because sizeof is a compile time operation. You can’t use it on things allocated dynamically at run time.

    (Besides, you already know the size of the data pointed to by file_data — it’s MAX_SIZE?)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to design a class that needs to dynamically allocate some memory.. I
I'm trying to create a function that would dynamically allocate an array, sets the
I am trying to dynamically allocate an array of structures in c so that
I am trying to dynamically make divs that are clickable. I have inserted a
I'm trying to dynamically construct URLs in an ASP.NET MVC website that point back
This question is in C++. I am trying to dynamically allocate an array of
Working through C++ Primer Plus and am trying to cin data to a dynamically
I am trying to dynamically load a user control in an asp.web site. However
I'm trying to keep a dynamically allocated array of strings that are read in
I am trying to dynamically allocate an array of base(Student) classes, and then assign

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.