In the android system, an attribute system is designed. What is it used? What are the advantages of this design? In fact, this attribute system is mainly used to save system configurations or exchange information of different processes. The biggest advantage of such a system is to unify the system configuration mode, unify the information exchange mode, and improve the system performance through Memory Sharing.
The following is the initialization function of the Property System. The Code is as follows:
#001 void property_init (void)
#002 {
#003 init_property_area ();
This line of code calls the init_property_area function to set the attribute memory area.
#004 load_properties_from_file (PROP_PATH_RAMDISK_DEFAULT );
This line of code loads the attribute file from the ramdisk disk.
#005}
In this function, you need to check the macro definition as follows:
# Define PROP_PATH_RAMDISK_DEFAULT "/default. prop"
That is, load the attribute file/default. prop from the memory disk and put these attributes into the attribute system.
Next, we will analyze how the init_property_area function creates the shared memory and put the property in it for all processes to share and use. The Code is as follows:
#001 static int init_property_area (void)
#002 {
#003 prop_area * pa;
#004
#005 if (pa_info_array)
#006 return-1;
This Code determines that when the attribute information array has been initialized, it will be returned directly.
#007
#008 if (init_workspace (& pa_workspace, PA_SIZE ))
#009 return-1;
This Code calls the init_workspace function to create the shared memory.
#010
#011 fcntl (pa_workspace.fd, F_SETFD, FD_CLOEXEC );
This line of code is used to disable shared memory after execution.
#012
#013 pa_info_array = (void *) (char *) pa_workspace.data) + PA_INFO_START );
This line of code is used to save and create a shared memory pointer.
#014
#015 pa = pa_workspace.data;
#016 memset (pa, 0, PA_SIZE );
This code clears the memory shared by the property.
#017 pa-> magic = PROP_AREA_MAGIC;
#018 pa-> version = PROP_AREA_VERSION;
This Code sets the version number of the attribute shared memory.
#019
#020/* plug into the lib property services */
#021 _ system_property_area _ = pa;
This line of code sets the attribute shared memory to be used by the attribute shared service of the database.
#022
#023 return 0;
#024}
#025
From the above function, we can see a function for creating shared memory. How does it create shared memory? Analyze its code now